<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" lang="en">

<head>
  <link href='https://fonts.googleapis.com/css?family=Inconsolata' rel='stylesheet' type='text/css' /><title>db.collection.update() &mdash; MongoDB Manual</title><link rel="shortcut icon" href="https://media.mongodb.org/favicon.ico" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="robots" content="index" />

  <meta name="release" content="4.2.5"/>
  <meta name="version" content="4.2"/>
  <meta name="DC.Source" content="https://github.com/mongodb/docs/blob/v4.2/source/reference/method/db.collection.update.txt"/>
  <meta property="og:image" content="http://s3.amazonaws.com/info-mongodb-com/_com_assets/cms/mongodb-for-giant-ideas-bbab5c3cf8.png">
  <meta property="og:image:secure_url" content="https://webassets.mongodb.com/_com_assets/cms/mongodb-for-giant-ideas-bbab5c3cf8.png">
      <link rel="canonical" href="https://docs.mongodb.com/manual/reference/method/db.collection.update" />
  
   <link rel="stylesheet" href="../../_static/mongodb-docs.css" type="text/css" />
   <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
   <link rel="stylesheet" href="../../_static/css/navbar.min.css" type="text/css" />
    
    <script type="text/javascript" src="../../_static/lib/jquery.min.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/lib/bootstrap.js"></script>
    <script type="text/javascript" src="../../_static/lib/jquery.cookie.js"></script>
    <script type="text/javascript" src="../../_static/controller.js"></script>
      <link rel="search" type="application/opensearchdescription+xml" href="https://docs.mongodb.com/osd.xml" title="MongoDB Help"/>
<link rel="author" title="About these documents" href="../../about.html" />
<!-- <link rel="index" title="Index" href="../../genindex.html" /> -->
<link rel="search" title="Search" href="../../search.html" />
<link rel="top" title="MongoDB Manual" href="../../index.html" />
<link rel="up" title="Collection Methods" href="js-collection.html" />
<link rel="next" title="db.collection.updateOne()" href="db.collection.updateOne.html" />
<link rel="prev" title="db.collection.totalSize()" href="db.collection.totalSize.html" /><script type='text/javascript'>
   var gptadslots=[];
   var googletag = googletag || {};
   googletag.cmd = googletag.cmd || [];
   (function(){ var gads = document.createElement('script');
      gads.async = true; gads.type = 'text/javascript';
      var useSSL = 'https:' == document.location.protocol;
      gads.src = (useSSL ? 'https:' : 'http:') + '//www.googletagservices.com/tag/js/gpt.js';
      var node = document.getElementsByTagName('script')[0];
      node.parentNode.insertBefore(gads, node);
   })();
</script>

<script type="text/javascript">
   googletag.cmd.push(function() {

      var pathname = location.href;
      
      if ( (pathname.indexOf("auth") >= 0) || (pathname.indexOf("security") >= 0) ) {
         gptadslots[1]= googletag.defineSlot('/40039723/docs.mongodb.org/security', [[160,600],[243,202],[293,244]],'mongodb-docs-1').addService(googletag.pubads());
      } else if ( (pathname.indexOf("crud") >= 0) ||  (pathname.indexOf("query") >= 0) || (pathname.indexOf("insert") >= 0) || (pathname.indexOf("update") >= 0) || (pathname.indexOf("remove") >= 0) || (pathname.indexOf("delete") >= 0) || (pathname.indexOf("aggregation") >= 0) ) {
         gptadslots[1]= googletag.defineSlot('/40039723/docs.mongodb.org/crud', [[160,600],[243,202],[293,244]],'mongodb-docs-1').addService(googletag.pubads());
      } else if (pathname.indexOf("shard") >= 0) {
         gptadslots[1]= googletag.defineSlot('/40039723/docs.mongodb.org/sharding', [[160,600],[243,202],[293,244]],'mongodb-docs-1').addService(googletag.pubads());
      } else if (pathname.indexOf("replica") >= 0) {
         gptadslots[1]= googletag.defineSlot('/40039723/docs.mongodb.org/replication', [[160,600],[243,202],[293,244]],'mongodb-docs-1').addService(googletag.pubads());
      } else if (pathname.indexOf("model") >= 0) {
         gptadslots[1]= googletag.defineSlot('/40039723/docs.mongodb.org/data-modeling', [[160,600],[243,202],[293,244]],'mongodb-docs-1').addService(googletag.pubads());
      } else if (pathname.indexOf("administration") >= 0) {
         gptadslots[1]= googletag.defineSlot('/40039723/docs.mongodb.org/support', [[160,600],[243,202],[293,244]],'mongodb-docs-1').addService(googletag.pubads());
      } else if (pathname.indexOf("install-mongodb-on-windows") >= 0) {
         gptadslots[1]= googletag.defineSlot('/40039723/docs.mongodb.org/install-mongodb-on-windows', [160, 600], 'mongodb-docs-1').addService(googletag.pubads());
      } else if (pathname.indexOf("tutorial/getting-started") >= 0) {
         gptadslots[1]= googletag.defineSlot('/40039723/docs.mongodb.org/docs_server_gettingstarted', [160, 600], 'mongodb-docs-1').addService(googletag.pubads());
      } else {
         //Adslot 1 declaration
         gptadslots[1]= googletag.defineSlot('/40039723/docs.mongodb.org', [[160,600],[243,202],[293,244]],'mongodb-docs-1').addService(googletag.pubads());
      }
      googletag.pubads().enableSingleRequest();
      googletag.pubads().enableAsyncRendering();
      googletag.enableServices();
   });
</script></head>
<body data-project="manual" data-project-title="MongoDB Manual" data-branch="v4.2" data-enable-marian=1>
  <!-- Google Tag Manager -->
  <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-JQHP"
                    height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
  <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push(
     {'gtm.start': new Date().getTime(),event:'gtm.js'}
   );var f=d.getElementsByTagName(s)[0],
   j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
   '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
   })(window,document,'script','dataLayer','GTM-JQHP');</script>
  <!-- End Google Tag Manager -->
<div id="navbar" data-navprops='{"links": [{"url": "https://docs.mongodb.com/manual/","text": "Server","active": true},{"url": "https://docs.mongodb.com/ecosystem/drivers/","text": "Drivers"},{"url": "https://docs.mongodb.com/cloud/","text": "Cloud"},{"url": "https://docs.mongodb.com/tools/","text": "Tools"},{"url": "https://docs.mongodb.com/guides/","text": "Guides"}]}'></div>
      <script>
        window.googleSearchCx = "017213726194841070573:WMX6838984"
	window.googleSearchPlaceholder = "Search Documentation"
        window.googleSearchResultsUrl = "http://docs.mongodb.com/manual/search/"
      </script>
    <script src="../../_static/navbar.min.js"></script>
  

  <div class="content" >

   <div id="left-column">
         <aside id="sidebar" class="sidebar">
             
  <div class="sphinxsidebar" id="sphinxsidebar">
    <div id="sphinxsidebarwrapper" class="sphinxsidebarwrapper"><a href="javascript:void(0)" class="closeNav" id="closeNav">Close &times;</a>


<h3>
  <a class="index-link" href="../../index.html">MongoDB Manual</a>
</h3>


    <div class="btn-group version-sidebar">
      <button type="button" class="version-button dropdown-toggle" data-toggle="dropdown">
        
        
        Version 4.2 (current)<span class="caret"></span>
      </button>
      <ul class="dropdown-menu" role="menu">
        
          
          <li>
          
            <a class="version-selector" href="#" data-path="master">
              
              Version 4.4 (upcoming)
            </a>
          </li>
        
          
          <li class="active">
          
            <a href="#" data-path="manual">
              
              Version 4.2 (current)
            </a>
          </li>
        
          
          <li>
          
            <a class="version-selector" href="#" data-path="v4.0">
              
              Version 4.0
            </a>
          </li>
        
          
          <li>
          
            <a class="version-selector" href="#" data-path="v3.6">
              
              Version 3.6
            </a>
          </li>
        
          
          <li>
          
            <a class="version-selector" href="#" data-path="v3.4">
              
              Version 3.4
            </a>
          </li>
        
          
          <li>
          
            <a class="version-selector" href="#" data-path="v3.2">
              
              Version 3.2
            </a>
          </li>
        
          
          <li>
          
            <a class="version-selector" href="#" data-path="v3.0">
              
              Version 3.0
            </a>
          </li>
        
          
          <li>
          
            <a class="version-selector" href="#" data-path="v2.6">
              
              Version 2.6
            </a>
          </li>
        
          
          <li>
          
            <a class="version-selector" href="#" data-path="v2.4">
              
              Version 2.4
            </a>
          </li>
        
          
          <li>
          
            <a class="version-selector" href="#" data-path="v2.2">
              
              Version 2.2
            </a>
          </li>
        
      </ul>
    </div>


<ul class="current"><li class="toctree-l1"><a class="reference internal" href="../../introduction.html">Introduction</a><ul><li class="toctree-l2"><a class="reference internal" href="../../tutorial/getting-started.html">Getting Started</a></li><li class="toctree-l2"><a class="reference external" href="https://docs.atlas.mongodb.com/getting-started/">Create an Atlas Free Tier Cluster</a></li><li class="toctree-l2"><a class="reference internal" href="../../core/databases-and-collections.html">Databases and Collections</a><ul><li class="toctree-l3"><a class="reference internal" href="../../core/views.html">Views</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/materialized-views.html">On-Demand Materialized Views</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/capped-collections.html">Capped Collections</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/document.html">Documents</a></li><li class="toctree-l2"><a class="reference internal" href="../bson-types.html">BSON Types</a><ul><li class="toctree-l3"><a class="reference internal" href="../bson-type-comparison-order.html">Comparison/Sort Order</a></li><li class="toctree-l3"><a class="reference internal" href="../mongodb-extended-json.html">MongoDB Extended JSON (v2)</a></li><li class="toctree-l3"><a class="reference internal" href="../mongodb-extended-json-v1.html">MongoDB Extended JSON (v1)</a></li></ul></li></ul></li><li class="toctree-l1"><a class="reference internal" href="../../installation.html">Installation</a><ul><li class="toctree-l2"><a class="reference internal" href="../../administration/install-community.html">Install MongoDB Community Edition</a><ul><li class="toctree-l3"><a class="reference internal" href="../../administration/install-on-linux.html">Install on Linux</a><ul><li class="toctree-l4"><a class="reference internal" href="../../tutorial/install-mongodb-on-red-hat.html">Install on Red Hat</a><ul><li class="toctree-l5"><a class="reference internal" href="../../tutorial/install-mongodb-on-red-hat-tarball.html">Install using .tgz Tarball</a></li></ul></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/install-mongodb-on-ubuntu.html">Install on Ubuntu</a><ul><li class="toctree-l5"><a class="reference internal" href="../../tutorial/install-mongodb-on-ubuntu-tarball.html">Install using .tgz Tarball</a></li><li class="toctree-l5"><a class="reference internal" href="../installation-ubuntu-community-troubleshooting.html">Troubleshoot Ubuntu Installation</a></li></ul></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/install-mongodb-on-debian.html">Install on Debian</a><ul><li class="toctree-l5"><a class="reference internal" href="../../tutorial/install-mongodb-on-debian-tarball.html">Install using .tgz Tarball</a></li></ul></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/install-mongodb-on-suse.html">Install on SUSE</a><ul><li class="toctree-l5"><a class="reference internal" href="../../tutorial/install-mongodb-on-suse-tarball.html">Install using .tgz Tarball</a></li></ul></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/install-mongodb-on-amazon.html">Install on Amazon</a><ul><li class="toctree-l5"><a class="reference internal" href="../../tutorial/install-mongodb-on-amazon-tarball.html">Install using .tgz Tarball</a></li></ul></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/install-mongodb-on-os-x.html">Install on macOS</a><ul><li class="toctree-l4"><a class="reference internal" href="../../tutorial/install-mongodb-on-os-x-tarball.html">Install using .tgz Tarball</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/install-mongodb-on-windows.html">Install on Windows</a><ul><li class="toctree-l4"><a class="reference internal" href="../../tutorial/install-mongodb-on-windows-unattended.html">Install using msiexec.exe</a></li></ul></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../administration/install-enterprise.html">Install MongoDB Enterprise</a><ul><li class="toctree-l3"><a class="reference internal" href="../../administration/install-enterprise-linux.html">Install on Linux</a><ul><li class="toctree-l4"><a class="reference internal" href="../../tutorial/install-mongodb-enterprise-on-red-hat.html">Install on Red Hat</a><ul><li class="toctree-l5"><a class="reference internal" href="../../tutorial/install-mongodb-enterprise-on-red-hat-tarball.html">Install using .tgz Tarball</a></li></ul></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/install-mongodb-enterprise-on-ubuntu.html">Install on Ubuntu</a><ul><li class="toctree-l5"><a class="reference internal" href="../../tutorial/install-mongodb-enterprise-on-ubuntu-tarball.html">Install using .tgz Tarball</a></li></ul></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/install-mongodb-enterprise-on-debian.html">Install on Debian</a><ul><li class="toctree-l5"><a class="reference internal" href="../../tutorial/install-mongodb-enterprise-on-debian-tarball.html">Install using .tgz Tarball</a></li></ul></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/install-mongodb-enterprise-on-suse.html">Install on SUSE</a><ul><li class="toctree-l5"><a class="reference internal" href="../../tutorial/install-mongodb-enterprise-on-suse-tarball.html">Install using .tgz Tarball</a></li></ul></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/install-mongodb-enterprise-on-amazon.html">Install on Amazon</a><ul><li class="toctree-l5"><a class="reference internal" href="../../tutorial/install-mongodb-enterprise-on-amazon-tarball.html">Install using .tgz Tarball</a></li></ul></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/install-mongodb-enterprise-on-os-x.html">Install on macOS</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/install-mongodb-enterprise-on-windows.html">Install on Windows</a><ul><li class="toctree-l4"><a class="reference internal" href="../../tutorial/install-mongodb-enterprise-on-windows-unattended.html">Install using msiexec.exe</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/install-mongodb-enterprise-with-docker.html">Install with Docker</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../administration/upgrade-community-to-enterprise.html">Upgrade MongoDB Community to MongoDB Enterprise</a><ul><li class="toctree-l3"><a class="reference internal" href="../../tutorial/upgrade-to-enterprise-standalone.html">Upgrade to MongoDB Enterprise (Standalone)</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/upgrade-to-enterprise-replica-set.html">Upgrade to MongoDB Enterprise (Replica Set)</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/upgrade-to-enterprise-sharded-cluster.html">Upgrade to MongoDB Enterprise (Sharded Cluster)</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../tutorial/verify-mongodb-packages.html">Verify Integrity of MongoDB Packages</a></li></ul></li><li class="toctree-l1"><a class="reference internal" href="../../mongo.html">The <code class="docutils literal"><span class="pre">mongo</span></code> Shell</a><ul><li class="toctree-l2"><a class="reference internal" href="../../tutorial/configure-mongo-shell.html">Configure the <code class="docutils literal"><span class="pre">mongo</span></code> Shell</a></li><li class="toctree-l2"><a class="reference internal" href="../../tutorial/access-mongo-shell-help.html">Access the <code class="docutils literal"><span class="pre">mongo</span></code> Shell Help</a></li><li class="toctree-l2"><a class="reference internal" href="../../tutorial/write-scripts-for-the-mongo-shell.html">Write Scripts for the <code class="docutils literal"><span class="pre">mongo</span></code> Shell</a></li><li class="toctree-l2"><a class="reference internal" href="../../core/shell-types.html">Data Types in the <code class="docutils literal"><span class="pre">mongo</span></code> Shell</a></li><li class="toctree-l2"><a class="reference internal" href="../mongo-shell.html"><code class="docutils literal"><span class="pre">mongo</span></code> Shell Quick Reference</a></li></ul></li><li class="toctree-l1"><a class="reference internal" href="../../crud.html">MongoDB CRUD Operations</a><ul><li class="toctree-l2"><a class="reference internal" href="../../tutorial/insert-documents.html">Insert Documents</a><ul><li class="toctree-l3"><a class="reference internal" href="../insert-methods.html">Insert Methods</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../tutorial/query-documents.html">Query Documents</a><ul><li class="toctree-l3"><a class="reference internal" href="../../tutorial/query-embedded-documents.html">Query on Embedded/Nested Documents</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/query-arrays.html">Query an Array</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/query-array-of-documents.html">Query an Array of Embedded Documents</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/project-fields-from-query-results.html">Project Fields to Return from Query</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/query-for-null-fields.html">Query for Null or Missing Fields</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/iterate-a-cursor.html">Iterate a Cursor in the <code class="docutils literal"><span class="pre">mongo</span></code> Shell</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../tutorial/update-documents.html">Update Documents</a><ul><li class="toctree-l3"><a class="reference internal" href="../../tutorial/update-documents-with-aggregation-pipeline.html">Updates with Aggregation Pipeline</a></li><li class="toctree-l3"><a class="reference internal" href="../update-methods.html">Update Methods</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../tutorial/remove-documents.html">Delete Documents</a><ul><li class="toctree-l3"><a class="reference internal" href="../delete-methods.html">Delete Methods</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/bulk-write-operations.html">Bulk Write Operations</a></li><li class="toctree-l2"><a class="reference internal" href="../../core/retryable-writes.html">Retryable Writes</a></li><li class="toctree-l2"><a class="reference internal" href="../sql-comparison.html">SQL to MongoDB Mapping Chart</a></li><li class="toctree-l2"><a class="reference internal" href="../../text-search.html">Text Search</a><ul><li class="toctree-l3"><a class="reference internal" href="../../core/link-text-indexes.html">Text Indexes</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/text-search-operators.html">Text Search Operators</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/text-search-in-aggregation.html">Text Search in the Aggregation Pipeline</a></li><li class="toctree-l3"><a class="reference internal" href="../text-search-languages.html">Text Search Languages</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../geospatial-queries.html">Geospatial Queries</a><ul><li class="toctree-l3"><a class="reference internal" href="../../tutorial/geospatial-tutorial.html">Find Restaurants with Geospatial Queries</a></li><li class="toctree-l3"><a class="reference internal" href="../geojson.html">GeoJSON Objects</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../read-concern.html">Read Isolation (Read Concern)</a><ul><li class="toctree-l3"><a class="reference internal" href="../read-concern-local.html">Read Concern <code class="docutils literal"><span class="pre">&quot;local&quot;</span></code></a></li><li class="toctree-l3"><a class="reference internal" href="../read-concern-available.html">Read Concern <code class="docutils literal"><span class="pre">&quot;available&quot;</span></code></a></li><li class="toctree-l3"><a class="reference internal" href="../read-concern-majority.html">Read Concern <code class="docutils literal"><span class="pre">&quot;majority&quot;</span></code></a></li><li class="toctree-l3"><a class="reference internal" href="../read-concern-linearizable.html">Read Concern <code class="docutils literal"><span class="pre">&quot;linearizable&quot;</span></code></a></li><li class="toctree-l3"><a class="reference internal" href="../read-concern-snapshot.html">Read Concern <code class="docutils literal"><span class="pre">&quot;snapshot&quot;</span></code></a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../write-concern.html">Write Acknowledgement (Write Concern)</a></li><li class="toctree-l2"><a class="reference internal" href="../../core/crud.html">MongoDB CRUD Concepts</a><ul><li class="toctree-l3"><a class="reference internal" href="../../core/write-operations-atomicity.html">Atomicity and Transactions</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/read-isolation-consistency-recency.html">Read Isolation, Consistency, and Recency</a><ul><li class="toctree-l4"><a class="reference internal" href="../../core/causal-consistency-read-write-concerns.html">Causal Consistency and Read and Write Concerns</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../../core/distributed-queries.html">Distributed Queries</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/perform-findAndModify-linearizable-reads.html">Linearizable Reads via <code class="docutils literal"><span class="pre">findAndModify</span></code></a></li><li class="toctree-l3"><a class="reference internal" href="../../core/query-plans.html">Query Plans</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/query-optimization.html">Query Optimization</a><ul><li class="toctree-l4"><a class="reference internal" href="../../tutorial/evaluate-operation-performance.html">Evaluate Performance of Current Operations</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/optimize-query-performance-with-indexes-and-projections.html">Optimize Query Performance</a></li><li class="toctree-l4"><a class="reference internal" href="../../core/write-performance.html">Write Operation Performance</a></li><li class="toctree-l4"><a class="reference internal" href="../explain-results.html">Explain Results</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/analyze-query-plan.html">Analyze Query Performance</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/tailable-cursors.html">Tailable Cursors</a></li></ul></li></ul></li><li class="toctree-l1"><a class="reference internal" href="../../aggregation.html">Aggregation</a><ul><li class="toctree-l2"><a class="reference internal" href="../../core/aggregation-pipeline.html">Aggregation Pipeline</a><ul><li class="toctree-l3"><a class="reference internal" href="../../core/aggregation-pipeline-optimization.html">Aggregation Pipeline Optimization</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/aggregation-pipeline-limits.html">Aggregation Pipeline Limits</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/aggregation-pipeline-sharded-collections.html">Aggregation Pipeline and Sharded Collections</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/aggregation-zip-code-data-set.html">Example with ZIP Code Data</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/aggregation-with-user-preference-data.html">Example with User Preference Data</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/map-reduce.html">Map-Reduce</a><ul><li class="toctree-l3"><a class="reference internal" href="../../core/map-reduce-sharded-collections.html">Map-Reduce and Sharded Collections</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/map-reduce-concurrency.html">Map-Reduce Concurrency</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/map-reduce-examples.html">Map-Reduce Examples</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/perform-incremental-map-reduce.html">Perform Incremental Map-Reduce</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/troubleshoot-map-function.html">Troubleshoot the Map Function</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/troubleshoot-reduce-function.html">Troubleshoot the Reduce Function</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../aggregation.html">Aggregation Reference</a><ul><li class="toctree-l3"><a class="reference internal" href="../../meta/aggregation-quick-reference.html">Aggregation Pipeline Quick Reference</a></li><li class="toctree-l3"><a class="reference internal" href="../operator/aggregation/interface.html">Aggregation Commands</a></li><li class="toctree-l3"><a class="reference internal" href="../aggregation-commands-comparison.html">Aggregation Commands Comparison</a></li><li class="toctree-l3"><a class="reference internal" href="../aggregation-variables.html">Variables in Aggregation Expressions</a></li><li class="toctree-l3"><a class="reference internal" href="../sql-aggregation-comparison.html">SQL to Aggregation Mapping Chart</a></li></ul></li></ul></li><li class="toctree-l1"><a class="reference internal" href="../../data-modeling.html">Data Models</a><ul><li class="toctree-l2"><a class="reference internal" href="../../core/data-modeling-introduction.html">Data Modeling Introduction</a></li><li class="toctree-l2"><a class="reference internal" href="../../core/schema-validation.html">Schema Validation</a></li><li class="toctree-l2"><a class="reference internal" href="../../core/data-models.html">Data Modeling Concepts</a><ul><li class="toctree-l3"><a class="reference internal" href="../../core/data-model-design.html">Data Model Design</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/data-model-operations.html">Operational Factors and Data Models</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../applications/data-models.html">Data Model Examples and Patterns</a><ul><li class="toctree-l3"><a class="reference internal" href="../../applications/data-models-relationships.html">Model Relationships Between Documents</a><ul><li class="toctree-l4"><a class="reference internal" href="../../tutorial/model-embedded-one-to-one-relationships-between-documents.html">Model One-to-One Relationships with Embedded Documents</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/model-embedded-one-to-many-relationships-between-documents.html">Model One-to-Many Relationships with Embedded Documents</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/model-referenced-one-to-many-relationships-between-documents.html">Model One-to-Many Relationships with Document References</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../../applications/data-models-tree-structures.html">Model Tree Structures</a><ul><li class="toctree-l4"><a class="reference internal" href="../../tutorial/model-tree-structures-with-parent-references.html">Model Tree Structures with Parent References</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/model-tree-structures-with-child-references.html">Model Tree Structures with Child References</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/model-tree-structures-with-ancestors-array.html">Model Tree Structures with an Array of Ancestors</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/model-tree-structures-with-materialized-paths.html">Model Tree Structures with Materialized Paths</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/model-tree-structures-with-nested-sets.html">Model Tree Structures with Nested Sets</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../../applications/data-models-applications.html">Model Specific Application Contexts</a><ul><li class="toctree-l4"><a class="reference internal" href="../../tutorial/model-data-for-atomic-operations.html">Model Data for Atomic Operations</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/model-data-for-keyword-search.html">Model Data to Support Keyword Search</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/model-data-for-schema-versioning.html">Model Data for Schema Versioning</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/model-monetary-data.html">Model Monetary Data</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/model-time-data.html">Model Time Data</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/model-computed-data.html">Model Computed Data</a></li></ul></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../data-models.html">Data Model Reference</a><ul><li class="toctree-l3"><a class="reference internal" href="../database-references.html">Database References</a></li></ul></li></ul></li><li class="toctree-l1"><a class="reference internal" href="../../core/transactions.html">Transactions</a><ul><li class="toctree-l2"><a class="reference internal" href="../../core/transactions-in-applications.html">Drivers API</a></li><li class="toctree-l2"><a class="reference internal" href="../../core/transactions-production-consideration.html">Production Considerations</a></li><li class="toctree-l2"><a class="reference internal" href="../../core/transactions-sharded-clusters.html">Production Considerations (Sharded Clusters)</a></li><li class="toctree-l2"><a class="reference internal" href="../../core/transactions-operations.html">Transactions and Operations</a></li></ul></li><li class="toctree-l1"><a class="reference internal" href="../../indexes.html">Indexes</a><ul><li class="toctree-l2"><a class="reference internal" href="../../core/index-single.html">Single Field Indexes</a></li><li class="toctree-l2"><a class="reference internal" href="../../core/index-compound.html">Compound Indexes</a></li><li class="toctree-l2"><a class="reference internal" href="../../core/index-multikey.html">Multikey Indexes</a><ul><li class="toctree-l3"><a class="reference internal" href="../../core/multikey-index-bounds.html">Multikey Index Bounds</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/index-text.html">Text Indexes</a><ul><li class="toctree-l3"><a class="reference internal" href="../../tutorial/specify-language-for-text-index.html">Specify a Language for Text Index</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/avoid-text-index-name-limit.html">Specify Name for <code class="docutils literal"><span class="pre">text</span></code> Index</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/control-results-of-text-search.html">Control Search Results with Weights</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/limit-number-of-items-scanned-for-text-search.html">Limit the Number of Entries Scanned</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/index-wildcard.html">Wildcard Indexes</a><ul><li class="toctree-l3"><a class="reference internal" href="../index-wildcard-restrictions.html">Wildcard Index Restrictions</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/2dsphere.html"><code class="docutils literal"><span class="pre">2dsphere</span></code> Indexes</a><ul><li class="toctree-l3"><a class="reference internal" href="../../tutorial/query-a-2dsphere-index.html">Query a <code class="docutils literal"><span class="pre">2dsphere</span></code> Index</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/2d.html"><code class="docutils literal"><span class="pre">2d</span></code> Indexes</a><ul><li class="toctree-l3"><a class="reference internal" href="../../tutorial/build-a-2d-index.html">Create a <code class="docutils literal"><span class="pre">2d</span></code> Index</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/query-a-2d-index.html">Query a <code class="docutils literal"><span class="pre">2d</span></code> Index</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/geospatial-indexes.html"><code class="docutils literal"><span class="pre">2d</span></code> Index Internals</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/calculate-distances-using-spherical-geometry-with-2d-geospatial-indexes.html">Calculate Distance Using Spherical Geometry</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/geohaystack.html"><code class="docutils literal"><span class="pre">geoHaystack</span></code> Indexes</a><ul><li class="toctree-l3"><a class="reference internal" href="../../tutorial/build-a-geohaystack-index.html">Create a Haystack Index</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/query-a-geohaystack-index.html">Query a Haystack Index</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/index-hashed.html">Hashed Indexes</a></li><li class="toctree-l2"><a class="reference internal" href="../../core/index-properties.html">Index Properties</a><ul><li class="toctree-l3"><a class="reference internal" href="../../core/index-ttl.html">TTL Indexes</a><ul><li class="toctree-l4"><a class="reference internal" href="../../tutorial/expire-data.html">Expire Data from Collections by Setting TTL</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../../core/index-unique.html">Unique Indexes</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/index-partial.html">Partial Indexes</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/index-case-insensitive.html">Case Insensitive Indexes</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/index-sparse.html">Sparse Indexes</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/index-creation.html">Index Builds on Populated Collections</a><ul><li class="toctree-l3"><a class="reference internal" href="../../tutorial/build-indexes-on-replica-sets.html">Build Indexes on Replica Sets</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/build-indexes-on-sharded-clusters.html">Build Indexes on Sharded Clusters</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/index-intersection.html">Index Intersection</a></li><li class="toctree-l2"><a class="reference internal" href="../../tutorial/manage-indexes.html">Manage Indexes</a></li><li class="toctree-l2"><a class="reference internal" href="../../tutorial/measure-index-use.html">Measure Index Use</a></li><li class="toctree-l2"><a class="reference internal" href="../../applications/indexes.html">Indexing Strategies</a><ul><li class="toctree-l3"><a class="reference internal" href="../../tutorial/create-indexes-to-support-queries.html">Create Indexes to Support Your Queries</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/sort-results-with-indexes.html">Use Indexes to Sort Query Results</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/ensure-indexes-fit-ram.html">Ensure Indexes Fit in RAM</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/create-queries-that-ensure-selectivity.html">Create Queries that Ensure Selectivity</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../indexes.html">Indexing Reference</a></li></ul></li><li class="toctree-l1"><a class="reference internal" href="../../security.html">Security</a><ul><li class="toctree-l2"><a class="reference internal" href="../../administration/security-checklist.html">Security Checklist</a></li><li class="toctree-l2"><a class="reference internal" href="../../tutorial/enable-authentication.html">Enable Access Control</a></li><li class="toctree-l2"><a class="reference internal" href="../../core/authentication.html">Authentication</a><ul><li class="toctree-l3"><a class="reference internal" href="../../core/security-users.html">Users</a><ul><li class="toctree-l4"><a class="reference internal" href="../../tutorial/create-users.html">Add Users</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../../core/authentication-mechanisms.html">Authentication Mechanisms</a><ul><li class="toctree-l4"><a class="reference internal" href="../../core/security-scram.html">SCRAM</a></li><li class="toctree-l4"><a class="reference internal" href="../../core/security-x.509.html">x.509</a><ul><li class="toctree-l5"><a class="reference internal" href="../../tutorial/configure-x509-client-authentication.html">Use x.509 Certificates to Authenticate Clients</a></li></ul></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../../core/authentication-mechanisms-enterprise.html">Enterprise Authentication Mechanisms</a><ul><li class="toctree-l4"><a class="reference internal" href="../../core/kerberos.html">Kerberos Authentication</a><ul><li class="toctree-l5"><a class="reference internal" href="../../tutorial/control-access-to-mongodb-with-kerberos-authentication.html">Configure MongoDB with Kerberos Authentication on Linux</a></li><li class="toctree-l5"><a class="reference internal" href="../../tutorial/control-access-to-mongodb-windows-with-kerberos-authentication.html">Configure MongoDB with Kerberos Authentication on Windows</a></li><li class="toctree-l5"><a class="reference internal" href="../../tutorial/troubleshoot-kerberos.html">Troubleshoot Kerberos Authentication</a></li><li class="toctree-l5"><a class="reference internal" href="../../tutorial/kerberos-auth-activedirectory-authz.html">Configure MongoDB with Kerberos Authentication and Active Directory Authorization</a></li></ul></li><li class="toctree-l4"><a class="reference internal" href="../../core/security-ldap.html">LDAP Proxy Authentication</a><ul><li class="toctree-l5"><a class="reference internal" href="../../tutorial/configure-ldap-sasl-activedirectory.html">Authenticate Using SASL and LDAP with ActiveDirectory</a></li><li class="toctree-l5"><a class="reference internal" href="../../tutorial/configure-ldap-sasl-openldap.html">Authenticate Using SASL and LDAP with OpenLDAP</a></li><li class="toctree-l5"><a class="reference internal" href="../../tutorial/authenticate-nativeldap-activedirectory.html">Authenticate and Authorize Users Using Active Directory via Native LDAP</a></li></ul></li><li class="toctree-l4"><a class="reference internal" href="../../core/security-ldap-external.html">LDAP Authorization</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../../core/security-internal-authentication.html">Internal/Membership Authentication</a><ul><li class="toctree-l4"><a class="reference internal" href="../../tutorial/deploy-replica-set-with-keyfile-access-control.html">Deploy Replica Set With Keyfile Authentication</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/enforce-keyfile-access-control-in-existing-replica-set.html">Update Replica Set to Keyfile Authentication</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/enforce-keyfile-access-control-in-existing-replica-set-without-downtime.html">Update Replica Set to Keyfile Authentication (No Downtime)</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/rotate-key-replica-set.html">Rotate Keys for Replica Sets</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/deploy-sharded-cluster-with-keyfile-access-control.html">Deploy Sharded Cluster with Keyfile Authentication</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/enforce-keyfile-access-control-in-existing-sharded-cluster.html">Update Sharded Cluster to Keyfile Authentication</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/enforce-keyfile-access-control-in-existing-sharded-cluster-no-downtime.html">Update Sharded Cluster to Keyfile Authentication (No Downtime)</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/rotate-key-sharded-cluster.html">Rotate Keys for Sharded Clusters</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/configure-x509-member-authentication.html">Use x.509 Certificate for Membership Authentication</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/upgrade-keyfile-to-x509.html">Upgrade from Keyfile Authentication to x.509 Authentication</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/rotate-x509-membership-certificates.html">Rolling Update of x.509 Cluster Certificates that Contain New DN</a></li></ul></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/authorization.html">Role-Based Access Control</a><ul><li class="toctree-l3"><a class="reference internal" href="../built-in-roles.html">Built-In Roles</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/security-user-defined-roles.html">User-Defined Roles</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/manage-users-and-roles.html">Manage Users and Roles</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/change-own-password-and-custom-data.html">Change Your Password and Custom Data</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/collection-level-access-control.html">Collection-Level Access Control</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/security-transport-encryption.html">TLS/SSL (Transport Encryption)</a><ul><li class="toctree-l3"><a class="reference internal" href="../../tutorial/configure-ssl.html">Configure <code class="docutils literal"><span class="pre">mongod</span></code> and <code class="docutils literal"><span class="pre">mongos</span></code> for TLS/SSL</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/configure-ssl-clients.html">TLS/SSL Configuration for Clients</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/upgrade-cluster-to-ssl.html">Upgrade a Cluster to Use TLS/SSL</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/configure-fips.html">Configure MongoDB for FIPS</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/security-encryption-at-rest.html">Encryption at Rest</a><ul><li class="toctree-l3"><a class="reference internal" href="../../tutorial/configure-encryption.html">Configure Encryption</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/rotate-encryption-key.html">Rotate Encryption Keys</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/security-client-side-encryption.html">Client-Side Field Level Encryption</a><ul><li class="toctree-l3"><a class="reference internal" href="../../core/security-automatic-client-side-encryption.html">Automatic Client-Side Field Level Encryption</a><ul><li class="toctree-l4"><a class="reference internal" href="../security-client-side-automatic-json-schema.html">Automatic Encryption Rules</a></li><li class="toctree-l4"><a class="reference internal" href="../security-client-side-query-aggregation-support.html">Read/Write Support with Automatic Field Level Encryption</a></li><li class="toctree-l4"><a class="reference internal" href="../security-client-side-encryption-appendix.html">Appendix</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../../core/security-explicit-client-side-encryption.html">Explicit (Manual) Client-Side Field Level Encryption</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/security-client-side-encryption-key-management.html">Master Key and Data Encryption Key Management</a><ul><li class="toctree-l4"><a class="reference internal" href="../../tutorial/manage-client-side-encryption-data-keys.html">Manage Data Encryption Keys</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../security-client-side-encryption-limitations.html">Limitations</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/auditing.html">Auditing</a><ul><li class="toctree-l3"><a class="reference internal" href="../../tutorial/configure-auditing.html">Configure Auditing</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/configure-audit-filters.html">Configure Audit Filters</a></li><li class="toctree-l3"><a class="reference internal" href="../audit-message.html">System Event Audit Messages</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/security-hardening.html">Network and Configuration Hardening</a><ul><li class="toctree-l3"><a class="reference internal" href="../../core/security-mongodb-configuration.html">IP Binding</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/configure-linux-iptables-firewall.html">Configure Linux <code class="docutils literal"><span class="pre">iptables</span></code> Firewall for MongoDB</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/configure-windows-netsh-firewall.html">Configure Windows <code class="docutils literal"><span class="pre">netsh</span></code> Firewall for MongoDB</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../tutorial/implement-field-level-redaction.html">Implement Field Level Redaction</a></li><li class="toctree-l2"><a class="reference internal" href="../security.html">Security Reference</a><ul><li class="toctree-l3"><a class="reference internal" href="../system-roles-collection.html"><code class="docutils literal"><span class="pre">system.roles</span></code> Collection</a></li><li class="toctree-l3"><a class="reference internal" href="../system-users-collection.html"><code class="docutils literal"><span class="pre">system.users</span></code> Collection</a></li><li class="toctree-l3"><a class="reference internal" href="../resource-document.html">Resource Document</a></li><li class="toctree-l3"><a class="reference internal" href="../privilege-actions.html">Privilege Actions</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../tutorial/create-a-vulnerability-report.html">Create a Vulnerability Report</a></li><li class="toctree-l2"><a class="reference internal" href="../../appendix/security.html">Appendix</a><ul><li class="toctree-l3"><a class="reference internal" href="../../appendix/security/appendixA-openssl-ca.html">Appendix A - OpenSSL CA Certificate for Testing</a></li><li class="toctree-l3"><a class="reference internal" href="../../appendix/security/appendixB-openssl-server.html">Appendix B - OpenSSL Server Certificates for Testing</a></li><li class="toctree-l3"><a class="reference internal" href="../../appendix/security/appendixC-openssl-client.html">Appendix C - OpenSSL Client Certificates for Testing</a></li></ul></li></ul></li><li class="toctree-l1"><a class="reference internal" href="../../changeStreams.html">Change Streams</a><ul><li class="toctree-l2"><a class="reference internal" href="../../administration/change-streams-production-recommendations.html">Change Streams Production Recommendations</a></li><li class="toctree-l2"><a class="reference internal" href="../change-events.html">Change Events</a></li></ul></li><li class="toctree-l1"><a class="reference internal" href="../../replication.html">Replication</a><ul><li class="toctree-l2"><a class="reference internal" href="../../core/replica-set-members.html">Replica Set Members</a><ul><li class="toctree-l3"><a class="reference internal" href="../../core/replica-set-primary.html">Replica Set Primary</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/replica-set-secondary.html">Replica Set Secondary Members</a><ul><li class="toctree-l4"><a class="reference internal" href="../../core/replica-set-priority-0-member.html">Priority 0 Replica Set Members</a></li><li class="toctree-l4"><a class="reference internal" href="../../core/replica-set-hidden-member.html">Hidden Replica Set Members</a></li><li class="toctree-l4"><a class="reference internal" href="../../core/replica-set-delayed-member.html">Delayed Replica Set Members</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../../core/replica-set-arbiter.html">Replica Set Arbiter</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/replica-set-oplog.html">Replica Set Oplog</a></li><li class="toctree-l2"><a class="reference internal" href="../../core/replica-set-sync.html">Replica Set Data Synchronization</a></li><li class="toctree-l2"><a class="reference internal" href="../../core/replica-set-architectures.html">Replica Set Deployment Architectures</a><ul><li class="toctree-l3"><a class="reference internal" href="../../core/replica-set-architecture-three-members.html">Three Member Replica Sets</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/replica-set-architecture-geographically-distributed.html">Replica Sets Distributed Across Two or More Data Centers</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/replica-set-high-availability.html">Replica Set High Availability</a><ul><li class="toctree-l3"><a class="reference internal" href="../../core/replica-set-elections.html">Replica Set Elections</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/replica-set-rollbacks.html">Rollbacks During Replica Set Failover</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../applications/replication.html">Replica Set Read and Write Semantics</a><ul><li class="toctree-l3"><a class="reference internal" href="../../core/replica-set-write-concern.html">Write Concern for Replica Sets</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/read-preference.html">Read Preference</a><ul><li class="toctree-l4"><a class="reference internal" href="../../core/read-preference-tags.html">Tag Sets</a></li><li class="toctree-l4"><a class="reference internal" href="../../core/read-preference-staleness.html">maxStalenessSeconds</a></li><li class="toctree-l4"><a class="reference internal" href="../../core/read-preference-use-cases.html">Read Preference Use Cases</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../../core/read-preference-mechanics.html">Server Selection Algorithm</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../administration/replica-set-deployment.html">Replica Set Deployment Tutorials</a><ul><li class="toctree-l3"><a class="reference internal" href="../../tutorial/deploy-replica-set.html">Deploy a Replica Set</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/deploy-replica-set-for-testing.html">Deploy a Replica Set for Testing and Development</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/deploy-geographically-distributed-replica-set.html">Deploy a Geographically Redundant Replica Set</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/add-replica-set-arbiter.html">Add an Arbiter to Replica Set</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/convert-standalone-to-replica-set.html">Convert a Standalone to a Replica Set</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/expand-replica-set.html">Add Members to a Replica Set</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/remove-replica-set-member.html">Remove Members from Replica Set</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/replace-replica-set-member.html">Replace a Replica Set Member</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../administration/replica-set-member-configuration.html">Member Configuration Tutorials</a><ul><li class="toctree-l3"><a class="reference internal" href="../../tutorial/adjust-replica-set-member-priority.html">Adjust Priority for Replica Set Member</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/configure-secondary-only-replica-set-member.html">Prevent Secondary from Becoming Primary</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/configure-a-hidden-replica-set-member.html">Configure a Hidden Replica Set Member</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/configure-a-delayed-replica-set-member.html">Configure a Delayed Replica Set Member</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/configure-a-non-voting-replica-set-member.html">Configure Non-Voting Replica Set Member</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/convert-secondary-into-arbiter.html">Convert a Secondary to an Arbiter</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../administration/replica-set-maintenance.html">Replica Set Maintenance Tutorials</a><ul><li class="toctree-l3"><a class="reference internal" href="../../tutorial/change-oplog-size.html">Change the Size of the Oplog</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/perform-maintence-on-replica-set-members.html">Perform Maintenance on Replica Set Members</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/force-member-to-be-primary.html">Force a Member to Become Primary</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/resync-replica-set-member.html">Resync a Member of a Replica Set</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/configure-replica-set-tag-sets.html">Configure Replica Set Tag Sets</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/reconfigure-replica-set-with-unavailable-members.html">Reconfigure a Replica Set with Unavailable Members</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/manage-chained-replication.html">Manage Chained Replication</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/change-hostnames-in-a-replica-set.html">Change Hostnames in a Replica Set</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/configure-replica-set-secondary-sync-target.html">Configure a Secondary’s Sync Target</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../replication.html">Replication Reference</a><ul><li class="toctree-l3"><a class="reference internal" href="../replica-configuration.html">Replica Set Configuration</a></li><li class="toctree-l3"><a class="reference internal" href="../replica-set-protocol-versions.html">Replica Set Protocol Version</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/troubleshoot-replica-sets.html">Troubleshoot Replica Sets</a></li><li class="toctree-l3"><a class="reference internal" href="../local-database.html">The <code class="docutils literal"><span class="pre">local</span></code> Database</a></li><li class="toctree-l3"><a class="reference internal" href="../replica-states.html">Replica Set Member States</a></li></ul></li></ul></li><li class="toctree-l1"><a class="reference internal" href="../../sharding.html">Sharding</a><ul><li class="toctree-l2"><a class="reference internal" href="../../core/sharded-cluster-components.html">Sharded Cluster Components</a><ul><li class="toctree-l3"><a class="reference internal" href="../../core/sharded-cluster-shards.html">Shards</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/sharded-cluster-config-servers.html">Config Servers (metadata)</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/sharded-cluster-query-router.html">Router (mongos)</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/sharding-shard-key.html">Shard Keys</a></li><li class="toctree-l2"><a class="reference internal" href="../../core/hashed-sharding.html">Hashed Sharding</a></li><li class="toctree-l2"><a class="reference internal" href="../../core/ranged-sharding.html">Ranged Sharding</a></li><li class="toctree-l2"><a class="reference internal" href="../../tutorial/deploy-shard-cluster.html">Deploy a Sharded Cluster</a></li><li class="toctree-l2"><a class="reference internal" href="../../core/zone-sharding.html">Zones</a><ul><li class="toctree-l3"><a class="reference internal" href="../../tutorial/manage-shard-zone.html">Manage Shard Zones</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/sharding-segmenting-data-by-location.html">Segmenting Data by Location</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/sharding-tiered-hardware-for-varying-slas.html">Tiered Hardware for Varying SLA or SLO</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/sharding-segmenting-shards.html">Segmenting Data by Application or Customer</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/sharding-high-availability-writes.html">Distributed Local Writes for Insert Only Workloads</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/sharding-data-partitioning.html">Data Partitioning with Chunks</a><ul><li class="toctree-l3"><a class="reference internal" href="../../tutorial/create-chunks-in-sharded-cluster.html">Create Chunks in a Sharded Cluster</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/split-chunks-in-sharded-cluster.html">Split Chunks in a Sharded Cluster</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/merge-chunks-in-sharded-cluster.html">Merge Chunks in a Sharded Cluster</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/modify-chunk-size-in-sharded-cluster.html">Modify Chunk Size in a Sharded Cluster</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/sharding-balancer-administration.html">Balancer</a><ul><li class="toctree-l3"><a class="reference internal" href="../../tutorial/manage-sharded-cluster-balancer.html">Manage Sharded Cluster Balancer</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/migrate-chunks-in-sharded-cluster.html">Migrate Chunks in a Sharded Cluster</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../administration/sharded-cluster-administration.html">Administration</a><ul><li class="toctree-l3"><a class="reference internal" href="../../administration/sharded-cluster-config-servers.html">Config Server Administration</a><ul><li class="toctree-l4"><a class="reference internal" href="../../tutorial/replace-config-server.html">Replace a Config Server</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/view-sharded-cluster-configuration.html">View Cluster Configuration</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/restart-sharded-cluster.html">Restart a Sharded Cluster</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/migrate-sharded-cluster-to-new-hardware.html">Migrate a Sharded Cluster to Different Hardware</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/add-shards-to-shard-cluster.html">Add Shards to a Cluster</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/remove-shards-from-cluster.html">Remove Shards from an Existing Sharded Cluster</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/clear-jumbo-flag.html">Clear <code class="docutils literal"><span class="pre">jumbo</span></code> Flag</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/backup-sharded-cluster-metadata.html">Back Up Cluster Metadata</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/convert-sharded-cluster-to-replica-set.html">Convert Sharded Cluster to Replica Set</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/convert-replica-set-to-replicated-shard-cluster.html">Convert a Replica Set to a Sharded Cluster</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/convert-shard-standalone-to-shard-replica-set.html">Convert a Shard Standalone to a Shard Replica Set</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../sharding.html">Sharding Reference</a><ul><li class="toctree-l3"><a class="reference internal" href="../../core/sharded-cluster-requirements.html">Operational Restrictions</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/troubleshoot-sharded-clusters.html">Troubleshoot Sharded Clusters</a></li><li class="toctree-l3"><a class="reference internal" href="../config-database.html">Config Database</a></li></ul></li></ul></li><li class="toctree-l1"><a class="reference internal" href="../../administration.html">Administration</a><ul><li class="toctree-l2"><a class="reference internal" href="../../administration/production-notes.html">Production Notes</a></li><li class="toctree-l2"><a class="reference internal" href="../../administration/production-checklist-operations.html">Operations Checklist</a></li><li class="toctree-l2"><a class="reference internal" href="../../administration/production-checklist-development.html">Development Checklist</a></li><li class="toctree-l2"><a class="reference internal" href="../../administration/analyzing-mongodb-performance.html">Performance</a><ul><li class="toctree-l3"><a class="reference internal" href="../../tutorial/manage-the-database-profiler.html">Database Profiler</a><ul><li class="toctree-l4"><a class="reference internal" href="../database-profiler.html">Database Profiler Output</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/transparent-huge-pages.html">Disable Transparent Huge Pages (THP)</a></li><li class="toctree-l3"><a class="reference internal" href="../ulimit.html">UNIX <code class="docutils literal"><span class="pre">ulimit</span></code> Settings</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../administration/configuration-and-maintenance.html">Configuration and Maintenance</a><ul><li class="toctree-l3"><a class="reference internal" href="../../administration/configuration.html">Run-time Database Configuration</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/upgrade-revision.html">Upgrade to the Latest Revision of MongoDB</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/manage-mongodb-processes.html">Manage <code class="docutils literal"><span class="pre">mongod</span></code> Processes</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/terminate-running-operations.html">Terminate Running Operations</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/rotate-log-files.html">Rotate Log Files</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../data-center-awareness.html">Data Center Awareness</a><ul><li class="toctree-l3"><a class="reference internal" href="../../core/workload-isolation.html">Workload Isolation in MongoDB Deployments</a></li><li class="toctree-l3"><a class="reference internal" href="../../core/zone-sharding.html">Zones</a><ul><li class="toctree-l4"><a class="reference internal" href="../../tutorial/manage-shard-zone.html">Manage Shard Zones</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/sharding-segmenting-data-by-location.html">Segmenting Data by Location</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/sharding-tiered-hardware-for-varying-slas.html">Tiered Hardware for Varying SLA or SLO</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/sharding-segmenting-shards.html">Segmenting Data by Application or Customer</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/sharding-high-availability-writes.html">Distributed Local Writes for Insert Only Workloads</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/manage-shard-zone.html">Manage Shard Zones</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/backups.html">MongoDB Backup Methods</a><ul><li class="toctree-l3"><a class="reference internal" href="../../tutorial/backup-with-filesystem-snapshots.html">Back Up and Restore with Filesystem Snapshots</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/backup-and-restore-tools.html">Back Up and Restore with MongoDB Tools</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/restore-replica-set-from-backup.html">Restore a Replica Set from MongoDB Backups</a></li><li class="toctree-l3"><a class="reference internal" href="../../administration/backup-sharded-clusters.html">Backup and Restore Sharded Clusters</a><ul><li class="toctree-l4"><a class="reference internal" href="../../tutorial/backup-sharded-cluster-with-filesystem-snapshots.html">Back Up a Sharded Cluster with File System Snapshots</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/backup-sharded-cluster-with-database-dumps.html">Back Up a Sharded Cluster with Database Dumps</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/schedule-backup-window-for-sharded-clusters.html">Schedule Backup Window for Sharded Clusters</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/restore-sharded-cluster.html">Restore a Sharded Cluster</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/recover-data-following-unexpected-shutdown.html">Recover a Standalone after an Unexpected Shutdown</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../administration/monitoring.html">Monitoring for MongoDB</a><ul><li class="toctree-l3"><a class="reference internal" href="../../administration/free-monitoring.html">Free Monitoring</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/monitor-with-snmp.html">Monitor MongoDB With SNMP on Linux</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/monitor-with-snmp-on-windows.html">Monitor MongoDB Windows with SNMP</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/troubleshoot-snmp.html">Troubleshoot SNMP</a></li></ul></li></ul></li><li class="toctree-l1"><a class="reference internal" href="../../storage.html">Storage</a><ul><li class="toctree-l2"><a class="reference internal" href="../../core/storage-engines.html">Storage Engines</a><ul><li class="toctree-l3"><a class="reference internal" href="../../core/wiredtiger.html">WiredTiger Storage Engine</a><ul><li class="toctree-l4"><a class="reference internal" href="../../tutorial/change-standalone-wiredtiger.html">Change Standalone to WiredTiger</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/change-replica-set-wiredtiger.html">Change Replica Set to WiredTiger</a></li><li class="toctree-l4"><a class="reference internal" href="../../tutorial/change-sharded-cluster-wiredtiger.html">Change Sharded Cluster to WiredTiger</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../../core/inmemory.html">In-Memory Storage Engine</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/journaling.html">Journaling</a><ul><li class="toctree-l3"><a class="reference internal" href="../../tutorial/manage-journaling.html">Manage Journaling</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../core/gridfs.html">GridFS</a></li><li class="toctree-l2"><a class="reference internal" href="../../faq/storage.html">FAQ: MongoDB Storage</a></li></ul></li><li class="toctree-l1"><a class="reference internal" href="../../faq.html">Frequently Asked Questions</a><ul><li class="toctree-l2"><a class="reference internal" href="../../faq/fundamentals.html">FAQ: MongoDB Fundamentals</a></li><li class="toctree-l2"><a class="reference internal" href="../../faq/indexes.html">FAQ: Indexes</a></li><li class="toctree-l2"><a class="reference internal" href="../../faq/concurrency.html">FAQ: Concurrency</a></li><li class="toctree-l2"><a class="reference internal" href="../../faq/sharding.html">FAQ: Sharding with MongoDB</a></li><li class="toctree-l2"><a class="reference internal" href="../../faq/replica-sets.html">FAQ: Replication and Replica Sets</a></li><li class="toctree-l2"><a class="reference internal" href="../../faq/storage.html">FAQ: MongoDB Storage</a></li><li class="toctree-l2"><a class="reference internal" href="../../faq/diagnostics.html">FAQ: MongoDB Diagnostics</a></li></ul></li><li class="toctree-l1 current"><a class="reference internal" href="../../reference.html">Reference</a><ul class="current"><li class="toctree-l2"><a class="reference internal" href="../operator.html">Operators</a><ul><li class="toctree-l3"><a class="reference internal" href="../operator/query.html">Query and Projection Operators</a><ul><li class="toctree-l4"><a class="reference internal" href="../operator/query-comparison.html">Comparison Query Operators</a><ul><li class="toctree-l5"><a class="reference internal" href="../operator/query/eq.html">$eq</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/gt.html">$gt</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/gte.html">$gte</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/in.html">$in</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/lt.html">$lt</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/lte.html">$lte</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/ne.html">$ne</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/nin.html">$nin</a></li></ul></li><li class="toctree-l4"><a class="reference internal" href="../operator/query-logical.html">Logical Query Operators</a><ul><li class="toctree-l5"><a class="reference internal" href="../operator/query/and.html">$and</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/not.html">$not</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/nor.html">$nor</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/or.html">$or</a></li></ul></li><li class="toctree-l4"><a class="reference internal" href="../operator/query-element.html">Element Query Operators</a><ul><li class="toctree-l5"><a class="reference internal" href="../operator/query/exists.html">$exists</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/type.html">$type</a></li></ul></li><li class="toctree-l4"><a class="reference internal" href="../operator/query-evaluation.html">Evaluation Query Operators</a><ul><li class="toctree-l5"><a class="reference internal" href="../operator/query/expr.html">$expr</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/jsonSchema.html">$jsonSchema</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/mod.html">$mod</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/regex.html">$regex</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/text.html">$text</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/where.html">$where</a></li></ul></li><li class="toctree-l4"><a class="reference internal" href="../operator/query-geospatial.html">Geospatial Query Operators</a><ul><li class="toctree-l5"><a class="reference internal" href="../operator/query/geoIntersects.html">$geoIntersects</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/geoWithin.html">$geoWithin</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/near.html">$near</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/nearSphere.html">$nearSphere</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/box.html">$box</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/center.html">$center</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/centerSphere.html">$centerSphere</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/geometry.html">$geometry</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/maxDistance.html">$maxDistance</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/minDistance.html">$minDistance</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/polygon.html">$polygon</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/uniqueDocs.html">$uniqueDocs</a></li></ul></li><li class="toctree-l4"><a class="reference internal" href="../operator/query-array.html">Array Query Operators</a><ul><li class="toctree-l5"><a class="reference internal" href="../operator/query/all.html">$all</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/elemMatch.html">$elemMatch (query)</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/size.html">$size</a></li></ul></li><li class="toctree-l4"><a class="reference internal" href="../operator/query-bitwise.html">Bitwise Query Operators</a><ul><li class="toctree-l5"><a class="reference internal" href="../operator/query/bitsAllClear.html">$bitsAllClear</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/bitsAllSet.html">$bitsAllSet</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/bitsAnyClear.html">$bitsAnyClear</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/query/bitsAnySet.html">$bitsAnySet</a></li></ul></li><li class="toctree-l4"><a class="reference internal" href="../operator/query/comment.html">$comment</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/projection.html">Projection Operators</a><ul><li class="toctree-l5"><a class="reference internal" href="../operator/projection/positional.html">$ (projection)</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/projection/elemMatch.html">$elemMatch (projection)</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/projection/meta.html">$meta</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/projection/slice.html">$slice (projection)</a></li></ul></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../operator/update.html">Update Operators</a><ul><li class="toctree-l4"><a class="reference internal" href="../operator/update-field.html">Field Update Operators</a><ul><li class="toctree-l5"><a class="reference internal" href="../operator/update/currentDate.html">$currentDate</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/update/inc.html">$inc</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/update/min.html">$min</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/update/max.html">$max</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/update/mul.html">$mul</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/update/rename.html">$rename</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/update/set.html">$set</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/update/setOnInsert.html">$setOnInsert</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/update/unset.html">$unset</a></li></ul></li><li class="toctree-l4"><a class="reference internal" href="../operator/update-array.html">Array Update Operators</a><ul><li class="toctree-l5"><a class="reference internal" href="../operator/update/positional.html">$ (update)</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/update/positional-all.html">$[]</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/update/positional-filtered.html">$[&lt;identifier&gt;]</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/update/addToSet.html">$addToSet</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/update/pop.html">$pop</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/update/pull.html">$pull</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/update/push.html">$push</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/update/pullAll.html">$pullAll</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/update/each.html">$each</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/update/position.html">$position</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/update/slice.html">$slice</a></li><li class="toctree-l5"><a class="reference internal" href="../operator/update/sort.html">$sort</a></li></ul></li><li class="toctree-l4"><a class="reference internal" href="../operator/update-bitwise.html">Bitwise Update Operator</a><ul><li class="toctree-l5"><a class="reference internal" href="../operator/update/bit.html">$bit</a></li></ul></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../operator/aggregation-pipeline.html">Aggregation Pipeline Stages</a><ul><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/addFields.html">$addFields (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/bucket.html">$bucket (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/bucketAuto.html">$bucketAuto (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/collStats.html">$collStats (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/count.html">$count (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/currentOp.html">$currentOp (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/facet.html">$facet (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/geoNear.html">$geoNear (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/graphLookup.html">$graphLookup (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/group.html">$group (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/indexStats.html">$indexStats (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/limit.html">$limit (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/listLocalSessions.html">$listLocalSessions</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/listSessions.html">$listSessions</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/lookup.html">$lookup (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/match.html">$match (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/merge.html">$merge (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/out.html">$out (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/planCacheStats.html">$planCacheStats</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/project.html">$project (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/redact.html">$redact (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/replaceRoot.html">$replaceRoot (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/replaceWith.html">$replaceWith (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/sample.html">$sample (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/set.html">$set (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/skip.html">$skip (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/sort.html">$sort (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/sortByCount.html">$sortByCount (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/unset.html">$unset (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/unwind.html">$unwind (aggregation)</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../operator/aggregation.html">Aggregation Pipeline Operators</a><ul><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/abs.html">$abs (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/acos.html">$acos (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/acosh.html">$acosh (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/add.html">$add (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/addToSet.html">$addToSet (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/allElementsTrue.html">$allElementsTrue (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/and.html">$and (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/anyElementTrue.html">$anyElementTrue (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/arrayElemAt.html">$arrayElemAt (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/arrayToObject.html">$arrayToObject (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/asin.html">$asin (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/asinh.html">$asinh (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/atan.html">$atan (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/atan2.html">$atan2 (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/atanh.html">$atanh (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/avg.html">$avg (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/ceil.html">$ceil (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/cmp.html">$cmp (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/concat.html">$concat (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/concatArrays.html">$concatArrays (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/cond.html">$cond (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/convert.html">$convert (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/cos.html">$cos (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/dateFromParts.html">$dateFromParts (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/dateToParts.html">$dateToParts (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/dateFromString.html">$dateFromString (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/dateToString.html">$dateToString (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/dayOfMonth.html">$dayOfMonth (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/dayOfWeek.html">$dayOfWeek (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/dayOfYear.html">$dayOfYear (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/degreesToRadians.html">$degreesToRadians (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/divide.html">$divide (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/eq.html">$eq (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/exp.html">$exp (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/filter.html">$filter (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/first.html">$first (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/floor.html">$floor (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/gt.html">$gt (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/gte.html">$gte (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/hour.html">$hour (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/ifNull.html">$ifNull (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/in.html">$in (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/indexOfArray.html">$indexOfArray (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/indexOfBytes.html">$indexOfBytes (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/indexOfCP.html">$indexOfCP (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/isArray.html">$isArray (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/isoDayOfWeek.html">$isoDayOfWeek (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/isoWeek.html">$isoWeek (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/isoWeekYear.html">$isoWeekYear (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/last.html">$last (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/let.html">$let (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/literal.html">$literal (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/ln.html">$ln (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/log.html">$log (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/log10.html">$log10 (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/lt.html">$lt (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/lte.html">$lte (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/ltrim.html">$ltrim (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/map.html">$map (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/max.html">$max (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/mergeObjects.html">$mergeObjects (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/meta.html">$meta (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/min.html">$min (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/millisecond.html">$millisecond (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/minute.html">$minute (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/mod.html">$mod (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/month.html">$month (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/multiply.html">$multiply (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/ne.html">$ne (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/not.html">$not (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/objectToArray.html">$objectToArray (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/or.html">$or (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/pow.html">$pow (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/push.html">$push (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/radiansToDegrees.html">$radiansToDegrees (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/range.html">$range (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/reduce.html">$reduce (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/regexFind.html">$regexFind (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/regexFindAll.html">$regexFindAll (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/regexMatch.html">$regexMatch (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/reverseArray.html">$reverseArray (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/round.html">$round (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/rtrim.html">$rtrim (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/second.html">$second (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/setDifference.html">$setDifference (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/setEquals.html">$setEquals (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/setIntersection.html">$setIntersection (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/setIsSubset.html">$setIsSubset (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/setUnion.html">$setUnion (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/size.html">$size (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/sin.html">$sin (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/slice.html">$slice (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/split.html">$split (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/sqrt.html">$sqrt (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/stdDevPop.html">$stdDevPop (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/stdDevSamp.html">$stdDevSamp (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/strcasecmp.html">$strcasecmp (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/strLenBytes.html">$strLenBytes (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/strLenCP.html">$strLenCP (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/substr.html">$substr (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/substrBytes.html">$substrBytes (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/substrCP.html">$substrCP (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/subtract.html">$subtract (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/sum.html">$sum (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/switch.html">$switch (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/tan.html">$tan (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/toBool.html">$toBool (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/toDate.html">$toDate (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/toDecimal.html">$toDecimal (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/toDouble.html">$toDouble(aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/toInt.html">$toInt (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/toLong.html">$toLong (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/toObjectId.html">$toObjectId (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/toString.html">$toString (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/toLower.html">$toLower (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/toUpper.html">$toUpper (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/trim.html">$trim (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/trunc.html">$trunc (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/type.html">$type (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/week.html">$week (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/year.html">$year (aggregation)</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/aggregation/zip.html">$zip (aggregation)</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../operator/query-modifier.html">Query Modifiers</a><ul><li class="toctree-l4"><a class="reference internal" href="../operator/meta/comment.html">$comment</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/meta/explain.html">$explain</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/meta/hint.html">$hint</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/meta/max.html">$max</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/meta/maxTimeMS.html">$maxTimeMS</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/meta/min.html">$min</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/meta/orderby.html">$orderby</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/meta/query.html">$query</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/meta/returnKey.html">$returnKey</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/meta/showDiskLoc.html">$showDiskLoc</a></li><li class="toctree-l4"><a class="reference internal" href="../operator/meta/natural.html">$natural</a></li></ul></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../command.html">Database Commands</a><ul><li class="toctree-l3"><a class="reference internal" href="../command/nav-aggregation.html">Aggregation Commands</a><ul><li class="toctree-l4"><a class="reference internal" href="../command/aggregate.html">aggregate</a></li><li class="toctree-l4"><a class="reference internal" href="../command/count.html">count</a></li><li class="toctree-l4"><a class="reference internal" href="../command/distinct.html">distinct</a></li><li class="toctree-l4"><a class="reference internal" href="../command/mapReduce.html">mapReduce</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../command/nav-geospatial.html">Geospatial Commands</a><ul><li class="toctree-l4"><a class="reference internal" href="../command/geoSearch.html">geoSearch</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../command/nav-crud.html">Query and Write Operation Commands</a><ul><li class="toctree-l4"><a class="reference internal" href="../command/delete.html">delete</a></li><li class="toctree-l4"><a class="reference internal" href="../command/find.html">find</a></li><li class="toctree-l4"><a class="reference internal" href="../command/findAndModify.html">findAndModify</a></li><li class="toctree-l4"><a class="reference internal" href="../command/getLastError.html">getLastError</a></li><li class="toctree-l4"><a class="reference internal" href="../command/getMore.html">getMore</a></li><li class="toctree-l4"><a class="reference internal" href="../command/insert.html">insert</a></li><li class="toctree-l4"><a class="reference internal" href="../command/resetError.html">resetError</a></li><li class="toctree-l4"><a class="reference internal" href="../command/update.html">update</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../command/nav-plan-cache.html">Query Plan Cache Commands</a><ul><li class="toctree-l4"><a class="reference internal" href="../command/planCacheClear.html">planCacheClear</a></li><li class="toctree-l4"><a class="reference internal" href="../command/planCacheClearFilters.html">planCacheClearFilters</a></li><li class="toctree-l4"><a class="reference internal" href="../command/planCacheListFilters.html">planCacheListFilters</a></li><li class="toctree-l4"><a class="reference internal" href="../command/planCacheListPlans.html">planCacheListPlans</a></li><li class="toctree-l4"><a class="reference internal" href="../command/planCacheListQueryShapes.html">planCacheListQueryShapes</a></li><li class="toctree-l4"><a class="reference internal" href="../command/planCacheSetFilter.html">planCacheSetFilter</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../command/nav-authentication.html">Authentication Commands</a><ul><li class="toctree-l4"><a class="reference internal" href="../command/authenticate.html">authenticate</a></li><li class="toctree-l4"><a class="reference internal" href="../command/getnonce.html">getnonce</a></li><li class="toctree-l4"><a class="reference internal" href="../command/logout.html">logout</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../command/nav-user-management.html">User Management Commands</a><ul><li class="toctree-l4"><a class="reference internal" href="../command/createUser.html">createUser</a></li><li class="toctree-l4"><a class="reference internal" href="../command/dropAllUsersFromDatabase.html">dropAllUsersFromDatabase</a></li><li class="toctree-l4"><a class="reference internal" href="../command/dropUser.html">dropUser</a></li><li class="toctree-l4"><a class="reference internal" href="../command/grantRolesToUser.html">grantRolesToUser</a></li><li class="toctree-l4"><a class="reference internal" href="../command/revokeRolesFromUser.html">revokeRolesFromUser</a></li><li class="toctree-l4"><a class="reference internal" href="../command/updateUser.html">updateUser</a></li><li class="toctree-l4"><a class="reference internal" href="../command/usersInfo.html">usersInfo</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../command/nav-role-management.html">Role Management Commands</a><ul><li class="toctree-l4"><a class="reference internal" href="../command/createRole.html">createRole</a></li><li class="toctree-l4"><a class="reference internal" href="../command/dropRole.html">dropRole</a></li><li class="toctree-l4"><a class="reference internal" href="../command/dropAllRolesFromDatabase.html">dropAllRolesFromDatabase</a></li><li class="toctree-l4"><a class="reference internal" href="../command/grantPrivilegesToRole.html">grantPrivilegesToRole</a></li><li class="toctree-l4"><a class="reference internal" href="../command/grantRolesToRole.html">grantRolesToRole</a></li><li class="toctree-l4"><a class="reference internal" href="../command/invalidateUserCache.html">invalidateUserCache</a></li><li class="toctree-l4"><a class="reference internal" href="../command/revokePrivilegesFromRole.html">revokePrivilegesFromRole</a></li><li class="toctree-l4"><a class="reference internal" href="../command/revokeRolesFromRole.html">revokeRolesFromRole</a></li><li class="toctree-l4"><a class="reference internal" href="../command/rolesInfo.html">rolesInfo</a></li><li class="toctree-l4"><a class="reference internal" href="../command/updateRole.html">updateRole</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../command/nav-replication.html">Replication Commands</a><ul><li class="toctree-l4"><a class="reference internal" href="../command/applyOps.html">applyOps</a></li><li class="toctree-l4"><a class="reference internal" href="../command/isMaster.html">isMaster</a></li><li class="toctree-l4"><a class="reference internal" href="../command/replSetAbortPrimaryCatchUp.html">replSetAbortPrimaryCatchUp</a></li><li class="toctree-l4"><a class="reference internal" href="../command/replSetFreeze.html">replSetFreeze</a></li><li class="toctree-l4"><a class="reference internal" href="../command/replSetGetConfig.html">replSetGetConfig</a></li><li class="toctree-l4"><a class="reference internal" href="../command/replSetGetStatus.html">replSetGetStatus</a></li><li class="toctree-l4"><a class="reference internal" href="../command/replSetInitiate.html">replSetInitiate</a></li><li class="toctree-l4"><a class="reference internal" href="../command/replSetMaintenance.html">replSetMaintenance</a></li><li class="toctree-l4"><a class="reference internal" href="../command/replSetReconfig.html">replSetReconfig</a></li><li class="toctree-l4"><a class="reference internal" href="../command/replSetResizeOplog.html">replSetResizeOplog</a></li><li class="toctree-l4"><a class="reference internal" href="../command/replSetStepDown.html">replSetStepDown</a></li><li class="toctree-l4"><a class="reference internal" href="../command/replSetSyncFrom.html">replSetSyncFrom</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../command/nav-sharding.html">Sharding Commands</a><ul><li class="toctree-l4"><a class="reference internal" href="../command/addShard.html">addShard</a></li><li class="toctree-l4"><a class="reference internal" href="../command/addShardToZone.html">addShardToZone</a></li><li class="toctree-l4"><a class="reference internal" href="../command/balancerStart.html">balancerStart</a></li><li class="toctree-l4"><a class="reference internal" href="../command/balancerStatus.html">balancerStatus</a></li><li class="toctree-l4"><a class="reference internal" href="../command/balancerStop.html">balancerStop</a></li><li class="toctree-l4"><a class="reference internal" href="../command/checkShardingIndex.html">checkShardingIndex</a></li><li class="toctree-l4"><a class="reference internal" href="../command/clearJumboFlag.html">clearJumboFlag</a></li><li class="toctree-l4"><a class="reference internal" href="../command/cleanupOrphaned.html">cleanupOrphaned</a></li><li class="toctree-l4"><a class="reference internal" href="../command/enableSharding.html">enableSharding</a></li><li class="toctree-l4"><a class="reference internal" href="../command/flushRouterConfig.html">flushRouterConfig</a></li><li class="toctree-l4"><a class="reference internal" href="../command/getShardMap.html">getShardMap</a></li><li class="toctree-l4"><a class="reference internal" href="../command/getShardVersion.html">getShardVersion</a></li><li class="toctree-l4"><a class="reference internal" href="../command/isdbgrid.html">isdbgrid</a></li><li class="toctree-l4"><a class="reference internal" href="../command/listShards.html">listShards</a></li><li class="toctree-l4"><a class="reference internal" href="../command/medianKey.html">medianKey</a></li><li class="toctree-l4"><a class="reference internal" href="../command/moveChunk.html">moveChunk</a></li><li class="toctree-l4"><a class="reference internal" href="../command/movePrimary.html">movePrimary</a></li><li class="toctree-l4"><a class="reference internal" href="../command/mergeChunks.html">mergeChunks</a></li><li class="toctree-l4"><a class="reference internal" href="../command/removeShard.html">removeShard</a></li><li class="toctree-l4"><a class="reference internal" href="../command/removeShardFromZone.html">removeShardFromZone</a></li><li class="toctree-l4"><a class="reference internal" href="../command/setShardVersion.html">setShardVersion</a></li><li class="toctree-l4"><a class="reference internal" href="../command/shardCollection.html">shardCollection</a></li><li class="toctree-l4"><a class="reference internal" href="../command/shardingState.html">shardingState</a></li><li class="toctree-l4"><a class="reference internal" href="../command/split.html">split</a></li><li class="toctree-l4"><a class="reference internal" href="../command/splitChunk.html">splitChunk</a></li><li class="toctree-l4"><a class="reference internal" href="../command/splitVector.html">splitVector</a></li><li class="toctree-l4"><a class="reference internal" href="../command/unsetSharding.html">unsetSharding</a></li><li class="toctree-l4"><a class="reference internal" href="../command/updateZoneKeyRange.html">updateZoneKeyRange</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../command/nav-sessions.html">Sessions Commands</a><ul><li class="toctree-l4"><a class="reference internal" href="../command/abortTransaction.html">abortTransaction</a></li><li class="toctree-l4"><a class="reference internal" href="../command/commitTransaction.html">commitTransaction</a></li><li class="toctree-l4"><a class="reference internal" href="../command/endSessions.html">endSessions</a></li><li class="toctree-l4"><a class="reference internal" href="../command/killAllSessions.html">killAllSessions</a></li><li class="toctree-l4"><a class="reference internal" href="../command/killAllSessionsByPattern.html">killAllSessionsByPattern</a></li><li class="toctree-l4"><a class="reference internal" href="../command/killSessions.html">killSessions</a></li><li class="toctree-l4"><a class="reference internal" href="../command/refreshSessions.html">refreshSessions</a></li><li class="toctree-l4"><a class="reference internal" href="../command/startSession.html">startSession</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../command/nav-administration.html">Administration Commands</a><ul><li class="toctree-l4"><a class="reference internal" href="../command/clean.html">clean</a></li><li class="toctree-l4"><a class="reference internal" href="../command/cloneCollection.html">cloneCollection</a></li><li class="toctree-l4"><a class="reference internal" href="../command/cloneCollectionAsCapped.html">cloneCollectionAsCapped</a></li><li class="toctree-l4"><a class="reference internal" href="../command/collMod.html">collMod</a></li><li class="toctree-l4"><a class="reference internal" href="../command/compact.html">compact</a></li><li class="toctree-l4"><a class="reference internal" href="../command/connPoolSync.html">connPoolSync</a></li><li class="toctree-l4"><a class="reference internal" href="../command/convertToCapped.html">convertToCapped</a></li><li class="toctree-l4"><a class="reference internal" href="../command/create.html">create</a></li><li class="toctree-l4"><a class="reference internal" href="../command/createIndexes.html">createIndexes</a></li><li class="toctree-l4"><a class="reference internal" href="../command/currentOp.html">currentOp</a></li><li class="toctree-l4"><a class="reference internal" href="../command/drop.html">drop</a></li><li class="toctree-l4"><a class="reference internal" href="../command/dropDatabase.html">dropDatabase</a></li><li class="toctree-l4"><a class="reference internal" href="../command/dropConnections.html">dropConnections</a></li><li class="toctree-l4"><a class="reference internal" href="../command/dropIndexes.html">dropIndexes</a></li><li class="toctree-l4"><a class="reference internal" href="../command/filemd5.html">filemd5</a></li><li class="toctree-l4"><a class="reference internal" href="../command/fsync.html">fsync</a></li><li class="toctree-l4"><a class="reference internal" href="../command/fsyncUnlock.html">fsyncUnlock</a></li><li class="toctree-l4"><a class="reference internal" href="../command/getParameter.html">getParameter</a></li><li class="toctree-l4"><a class="reference internal" href="../command/killCursors.html">killCursors</a></li><li class="toctree-l4"><a class="reference internal" href="../command/killOp.html">killOp</a></li><li class="toctree-l4"><a class="reference internal" href="../command/listCollections.html">listCollections</a></li><li class="toctree-l4"><a class="reference internal" href="../command/listDatabases.html">listDatabases</a></li><li class="toctree-l4"><a class="reference internal" href="../command/listIndexes.html">listIndexes</a></li><li class="toctree-l4"><a class="reference internal" href="../command/logRotate.html">logRotate</a></li><li class="toctree-l4"><a class="reference internal" href="../command/reIndex.html">reIndex</a></li><li class="toctree-l4"><a class="reference internal" href="../command/renameCollection.html">renameCollection</a></li><li class="toctree-l4"><a class="reference internal" href="../command/setFeatureCompatibilityVersion.html">setFeatureCompatibilityVersion</a></li><li class="toctree-l4"><a class="reference internal" href="../command/setParameter.html">setParameter</a></li><li class="toctree-l4"><a class="reference internal" href="../command/shutdown.html">shutdown</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../command/nav-diagnostic.html">Diagnostic Commands</a><ul><li class="toctree-l4"><a class="reference internal" href="../command/availableQueryOptions.html">availableQueryOptions</a></li><li class="toctree-l4"><a class="reference internal" href="../command/buildInfo.html">buildInfo</a></li><li class="toctree-l4"><a class="reference internal" href="../command/collStats.html">collStats</a></li><li class="toctree-l4"><a class="reference internal" href="../command/connPoolStats.html">connPoolStats</a></li><li class="toctree-l4"><a class="reference internal" href="../command/connectionStatus.html">connectionStatus</a></li><li class="toctree-l4"><a class="reference internal" href="../command/cursorInfo.html">cursorInfo</a></li><li class="toctree-l4"><a class="reference internal" href="../command/dataSize.html">dataSize</a></li><li class="toctree-l4"><a class="reference internal" href="../command/dbHash.html">dbHash</a></li><li class="toctree-l4"><a class="reference internal" href="../command/dbStats.html">dbStats</a></li><li class="toctree-l4"><a class="reference internal" href="../command/diagLogging.html">diagLogging</a></li><li class="toctree-l4"><a class="reference internal" href="../command/driverOIDTest.html">driverOIDTest</a></li><li class="toctree-l4"><a class="reference internal" href="../command/explain.html">explain</a></li><li class="toctree-l4"><a class="reference internal" href="../command/features.html">features</a></li><li class="toctree-l4"><a class="reference internal" href="../command/getCmdLineOpts.html">getCmdLineOpts</a></li><li class="toctree-l4"><a class="reference internal" href="../command/getLog.html">getLog</a></li><li class="toctree-l4"><a class="reference internal" href="../command/hostInfo.html">hostInfo</a></li><li class="toctree-l4"><a class="reference internal" href="../command/isSelf.html">isSelf</a></li><li class="toctree-l4"><a class="reference internal" href="../command/listCommands.html">listCommands</a></li><li class="toctree-l4"><a class="reference internal" href="../command/netstat.html">netstat</a></li><li class="toctree-l4"><a class="reference internal" href="../command/ping.html">ping</a></li><li class="toctree-l4"><a class="reference internal" href="../command/profile.html">profile</a></li><li class="toctree-l4"><a class="reference internal" href="../command/serverStatus.html">serverStatus</a></li><li class="toctree-l4"><a class="reference internal" href="../command/shardConnPoolStats.html">shardConnPoolStats</a></li><li class="toctree-l4"><a class="reference internal" href="../command/top.html">top</a></li><li class="toctree-l4"><a class="reference internal" href="../command/validate.html">validate</a></li><li class="toctree-l4"><a class="reference internal" href="../command/whatsmyuri.html">whatsmyuri</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../command/nav-free-monitoring.html">Free Monitoring Commands</a><ul><li class="toctree-l4"><a class="reference internal" href="../command/getFreeMonitoringStatus.html">getFreeMonitoringStatus</a></li><li class="toctree-l4"><a class="reference internal" href="../command/setFreeMonitoring.html">setFreeMonitoring</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../command/nav-auditing.html">System Events Auditing Commands</a><ul><li class="toctree-l4"><a class="reference internal" href="../command/logApplicationMessage.html">logApplicationMessage</a></li></ul></li></ul></li><li class="toctree-l2 current"><a class="reference internal" href="../method.html"><code class="docutils literal"><span class="pre">mongo</span></code> Shell Methods</a><ul class="current"><li class="toctree-l3 current"><a class="reference internal" href="js-collection.html">Collection Methods</a><ul class="current"><li class="toctree-l4"><a class="reference internal" href="db.collection.aggregate.html">db.collection.aggregate()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.bulkWrite.html">db.collection.bulkWrite()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.copyTo.html">db.collection.copyTo()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.count.html">db.collection.count()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.countDocuments.html">db.collection.countDocuments()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.estimatedDocumentCount.html">db.collection.estimatedDocumentCount()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.createIndex.html">db.collection.createIndex()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.createIndexes.html">db.collection.createIndexes()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.dataSize.html">db.collection.dataSize()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.deleteOne.html">db.collection.deleteOne()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.deleteMany.html">db.collection.deleteMany()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.distinct.html">db.collection.distinct()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.drop.html">db.collection.drop()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.dropIndex.html">db.collection.dropIndex()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.dropIndexes.html">db.collection.dropIndexes()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.ensureIndex.html">db.collection.ensureIndex()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.explain.html">db.collection.explain()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.find.html">db.collection.find()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.findAndModify.html">db.collection.findAndModify()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.findOne.html">db.collection.findOne()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.findOneAndDelete.html">db.collection.findOneAndDelete()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.findOneAndReplace.html">db.collection.findOneAndReplace()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.findOneAndUpdate.html">db.collection.findOneAndUpdate()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.getIndexes.html">db.collection.getIndexes()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.getShardDistribution.html">db.collection.getShardDistribution()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.getShardVersion.html">db.collection.getShardVersion()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.insert.html">db.collection.insert()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.insertOne.html">db.collection.insertOne()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.insertMany.html">db.collection.insertMany()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.isCapped.html">db.collection.isCapped()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.latencyStats.html">db.collection.latencyStats()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.mapReduce.html">db.collection.mapReduce()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.reIndex.html">db.collection.reIndex()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.remove.html">db.collection.remove()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.renameCollection.html">db.collection.renameCollection()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.replaceOne.html">db.collection.replaceOne()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.save.html">db.collection.save()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.stats.html">db.collection.stats()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.storageSize.html">db.collection.storageSize()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.totalIndexSize.html">db.collection.totalIndexSize()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.totalSize.html">db.collection.totalSize()</a></li><li class="toctree-l4 current"><a class="reference internal current" href="">db.collection.update()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.updateOne.html">db.collection.updateOne()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.updateMany.html">db.collection.updateMany()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.watch.html">db.collection.watch()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.validate.html">db.collection.validate()</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="js-cursor.html">Cursor Methods</a><ul><li class="toctree-l4"><a class="reference internal" href="cursor.addOption.html">cursor.addOption()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.allowPartialResults.html">cursor.allowPartialResults()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.batchSize.html">cursor.batchSize()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.close.html">cursor.close()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.isClosed.html">cursor.isClosed()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.collation.html">cursor.collation()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.comment.html">cursor.comment()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.count.html">cursor.count()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.explain.html">cursor.explain()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.forEach.html">cursor.forEach()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.hasNext.html">cursor.hasNext()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.hint.html">cursor.hint()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.isExhausted.html">cursor.isExhausted()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.itcount.html">cursor.itcount()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.limit.html">cursor.limit()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.map.html">cursor.map()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.max.html">cursor.max()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.maxTimeMS.html">cursor.maxTimeMS()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.min.html">cursor.min()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.next.html">cursor.next()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.noCursorTimeout.html">cursor.noCursorTimeout()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.objsLeftInBatch.html">cursor.objsLeftInBatch()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.pretty.html">cursor.pretty()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.readConcern.html">cursor.readConcern()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.readPref.html">cursor.readPref()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.returnKey.html">cursor.returnKey()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.showRecordId.html">cursor.showRecordId()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.size.html">cursor.size()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.skip.html">cursor.skip()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.sort.html">cursor.sort()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.tailable.html">cursor.tailable()</a></li><li class="toctree-l4"><a class="reference internal" href="cursor.toArray.html">cursor.toArray()</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="js-database.html">Database Methods</a><ul><li class="toctree-l4"><a class="reference internal" href="db.adminCommand.html">db.adminCommand()</a></li><li class="toctree-l4"><a class="reference internal" href="db.aggregate.html">db.aggregate()</a></li><li class="toctree-l4"><a class="reference internal" href="db.cloneCollection.html">db.cloneCollection()</a></li><li class="toctree-l4"><a class="reference internal" href="db.cloneDatabase.html">db.cloneDatabase()</a></li><li class="toctree-l4"><a class="reference internal" href="db.commandHelp.html">db.commandHelp()</a></li><li class="toctree-l4"><a class="reference internal" href="db.copyDatabase.html">db.copyDatabase()</a></li><li class="toctree-l4"><a class="reference internal" href="db.createCollection.html">db.createCollection()</a></li><li class="toctree-l4"><a class="reference internal" href="db.createView.html">db.createView()</a></li><li class="toctree-l4"><a class="reference internal" href="db.currentOp.html">db.currentOp()</a></li><li class="toctree-l4"><a class="reference internal" href="db.dropDatabase.html">db.dropDatabase()</a></li><li class="toctree-l4"><a class="reference internal" href="db.eval.html">db.eval()</a></li><li class="toctree-l4"><a class="reference internal" href="db.fsyncLock.html">db.fsyncLock()</a></li><li class="toctree-l4"><a class="reference internal" href="db.fsyncUnlock.html">db.fsyncUnlock()</a></li><li class="toctree-l4"><a class="reference internal" href="db.getCollection.html">db.getCollection()</a></li><li class="toctree-l4"><a class="reference internal" href="db.getCollectionInfos.html">db.getCollectionInfos()</a></li><li class="toctree-l4"><a class="reference internal" href="db.getCollectionNames.html">db.getCollectionNames()</a></li><li class="toctree-l4"><a class="reference internal" href="db.getLastError.html">db.getLastError()</a></li><li class="toctree-l4"><a class="reference internal" href="db.getLastErrorObj.html">db.getLastErrorObj()</a></li><li class="toctree-l4"><a class="reference internal" href="db.getLogComponents.html">db.getLogComponents()</a></li><li class="toctree-l4"><a class="reference internal" href="db.getMongo.html">db.getMongo()</a></li><li class="toctree-l4"><a class="reference internal" href="db.getName.html">db.getName()</a></li><li class="toctree-l4"><a class="reference internal" href="db.getProfilingLevel.html">db.getProfilingLevel()</a></li><li class="toctree-l4"><a class="reference internal" href="db.getProfilingStatus.html">db.getProfilingStatus()</a></li><li class="toctree-l4"><a class="reference internal" href="db.getReplicationInfo.html">db.getReplicationInfo()</a></li><li class="toctree-l4"><a class="reference internal" href="db.getSiblingDB.html">db.getSiblingDB()</a></li><li class="toctree-l4"><a class="reference internal" href="db.help.html">db.help()</a></li><li class="toctree-l4"><a class="reference internal" href="db.hostInfo.html">db.hostInfo()</a></li><li class="toctree-l4"><a class="reference internal" href="db.isMaster.html">db.isMaster()</a></li><li class="toctree-l4"><a class="reference internal" href="db.killOp.html">db.killOp()</a></li><li class="toctree-l4"><a class="reference internal" href="db.listCommands.html">db.listCommands()</a></li><li class="toctree-l4"><a class="reference internal" href="db.logout.html">db.logout()</a></li><li class="toctree-l4"><a class="reference internal" href="db.printCollectionStats.html">db.printCollectionStats()</a></li><li class="toctree-l4"><a class="reference internal" href="db.printReplicationInfo.html">db.printReplicationInfo()</a></li><li class="toctree-l4"><a class="reference internal" href="db.printShardingStatus.html">db.printShardingStatus()</a></li><li class="toctree-l4"><a class="reference internal" href="db.printSlaveReplicationInfo.html">db.printSlaveReplicationInfo()</a></li><li class="toctree-l4"><a class="reference internal" href="db.resetError.html">db.resetError()</a></li><li class="toctree-l4"><a class="reference internal" href="db.runCommand.html">db.runCommand()</a></li><li class="toctree-l4"><a class="reference internal" href="db.serverBuildInfo.html">db.serverBuildInfo()</a></li><li class="toctree-l4"><a class="reference internal" href="db.serverCmdLineOpts.html">db.serverCmdLineOpts()</a></li><li class="toctree-l4"><a class="reference internal" href="db.serverStatus.html">db.serverStatus()</a></li><li class="toctree-l4"><a class="reference internal" href="db.setLogLevel.html">db.setLogLevel()</a></li><li class="toctree-l4"><a class="reference internal" href="db.setProfilingLevel.html">db.setProfilingLevel()</a></li><li class="toctree-l4"><a class="reference internal" href="db.shutdownServer.html">db.shutdownServer()</a></li><li class="toctree-l4"><a class="reference internal" href="db.stats.html">db.stats()</a></li><li class="toctree-l4"><a class="reference internal" href="db.version.html">db.version()</a></li><li class="toctree-l4"><a class="reference internal" href="db.watch.html">db.watch()</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="js-plan-cache.html">Query Plan Cache Methods</a><ul><li class="toctree-l4"><a class="reference internal" href="db.collection.getPlanCache.html">db.collection.getPlanCache()</a></li><li class="toctree-l4"><a class="reference internal" href="PlanCache.clear.html">PlanCache.clear()</a></li><li class="toctree-l4"><a class="reference internal" href="PlanCache.clearPlansByQuery.html">PlanCache.clearPlansByQuery()</a></li><li class="toctree-l4"><a class="reference internal" href="PlanCache.getPlansByQuery.html">PlanCache.getPlansByQuery()</a></li><li class="toctree-l4"><a class="reference internal" href="PlanCache.help.html">PlanCache.help()</a></li><li class="toctree-l4"><a class="reference internal" href="PlanCache.listQueryShapes.html">PlanCache.listQueryShapes()</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="js-bulk.html">Bulk Operation Methods</a><ul><li class="toctree-l4"><a class="reference internal" href="db.collection.initializeOrderedBulkOp.html">db.collection.initializeOrderedBulkOp()</a></li><li class="toctree-l4"><a class="reference internal" href="db.collection.initializeUnorderedBulkOp.html">db.collection.initializeUnorderedBulkOp()</a></li><li class="toctree-l4"><a class="reference internal" href="Bulk.html">Bulk()</a></li><li class="toctree-l4"><a class="reference internal" href="Bulk.execute.html">Bulk.execute()</a></li><li class="toctree-l4"><a class="reference internal" href="Bulk.find.html">Bulk.find()</a></li><li class="toctree-l4"><a class="reference internal" href="Bulk.find.arrayFilters.html">Bulk.find.arrayFilters()</a></li><li class="toctree-l4"><a class="reference internal" href="Bulk.find.collation.html">Bulk.find.collation()</a></li><li class="toctree-l4"><a class="reference internal" href="Bulk.find.hint.html">Bulk.find.hint()</a></li><li class="toctree-l4"><a class="reference internal" href="Bulk.find.remove.html">Bulk.find.remove()</a></li><li class="toctree-l4"><a class="reference internal" href="Bulk.find.removeOne.html">Bulk.find.removeOne()</a></li><li class="toctree-l4"><a class="reference internal" href="Bulk.find.replaceOne.html">Bulk.find.replaceOne()</a></li><li class="toctree-l4"><a class="reference internal" href="Bulk.find.updateOne.html">Bulk.find.updateOne()</a></li><li class="toctree-l4"><a class="reference internal" href="Bulk.find.update.html">Bulk.find.update()</a></li><li class="toctree-l4"><a class="reference internal" href="Bulk.find.upsert.html">Bulk.find.upsert()</a></li><li class="toctree-l4"><a class="reference internal" href="Bulk.getOperations.html">Bulk.getOperations()</a></li><li class="toctree-l4"><a class="reference internal" href="Bulk.insert.html">Bulk.insert()</a></li><li class="toctree-l4"><a class="reference internal" href="Bulk.tojson.html">Bulk.tojson()</a></li><li class="toctree-l4"><a class="reference internal" href="Bulk.toString.html">Bulk.toString()</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="js-user-management.html">User Management Methods</a><ul><li class="toctree-l4"><a class="reference internal" href="db.auth.html">db.auth()</a></li><li class="toctree-l4"><a class="reference internal" href="db.changeUserPassword.html">db.changeUserPassword()</a></li><li class="toctree-l4"><a class="reference internal" href="db.createUser.html">db.createUser()</a></li><li class="toctree-l4"><a class="reference internal" href="db.dropUser.html">db.dropUser()</a></li><li class="toctree-l4"><a class="reference internal" href="db.dropAllUsers.html">db.dropAllUsers()</a></li><li class="toctree-l4"><a class="reference internal" href="db.getUser.html">db.getUser()</a></li><li class="toctree-l4"><a class="reference internal" href="db.getUsers.html">db.getUsers()</a></li><li class="toctree-l4"><a class="reference internal" href="db.grantRolesToUser.html">db.grantRolesToUser()</a></li><li class="toctree-l4"><a class="reference internal" href="db.removeUser.html">db.removeUser()</a></li><li class="toctree-l4"><a class="reference internal" href="db.revokeRolesFromUser.html">db.revokeRolesFromUser()</a></li><li class="toctree-l4"><a class="reference internal" href="db.updateUser.html">db.updateUser()</a></li><li class="toctree-l4"><a class="reference internal" href="passwordPrompt.html">passwordPrompt()</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="js-role-management.html">Role Management Methods</a><ul><li class="toctree-l4"><a class="reference internal" href="db.createRole.html">db.createRole()</a></li><li class="toctree-l4"><a class="reference internal" href="db.dropRole.html">db.dropRole()</a></li><li class="toctree-l4"><a class="reference internal" href="db.dropAllRoles.html">db.dropAllRoles()</a></li><li class="toctree-l4"><a class="reference internal" href="db.getRole.html">db.getRole()</a></li><li class="toctree-l4"><a class="reference internal" href="db.getRoles.html">db.getRoles()</a></li><li class="toctree-l4"><a class="reference internal" href="db.grantPrivilegesToRole.html">db.grantPrivilegesToRole()</a></li><li class="toctree-l4"><a class="reference internal" href="db.revokePrivilegesFromRole.html">db.revokePrivilegesFromRole()</a></li><li class="toctree-l4"><a class="reference internal" href="db.grantRolesToRole.html">db.grantRolesToRole()</a></li><li class="toctree-l4"><a class="reference internal" href="db.revokeRolesFromRole.html">db.revokeRolesFromRole()</a></li><li class="toctree-l4"><a class="reference internal" href="db.updateRole.html">db.updateRole()</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="js-replication.html">Replication Methods</a><ul><li class="toctree-l4"><a class="reference internal" href="rs.add.html">rs.add()</a></li><li class="toctree-l4"><a class="reference internal" href="rs.addArb.html">rs.addArb()</a></li><li class="toctree-l4"><a class="reference internal" href="rs.conf.html">rs.conf()</a></li><li class="toctree-l4"><a class="reference internal" href="rs.freeze.html">rs.freeze()</a></li><li class="toctree-l4"><a class="reference internal" href="rs.help.html">rs.help()</a></li><li class="toctree-l4"><a class="reference internal" href="rs.initiate.html">rs.initiate()</a></li><li class="toctree-l4"><a class="reference internal" href="rs.printReplicationInfo.html">rs.printReplicationInfo()</a></li><li class="toctree-l4"><a class="reference internal" href="rs.printSlaveReplicationInfo.html">rs.printSlaveReplicationInfo()</a></li><li class="toctree-l4"><a class="reference internal" href="rs.reconfig.html">rs.reconfig()</a></li><li class="toctree-l4"><a class="reference internal" href="rs.remove.html">rs.remove()</a></li><li class="toctree-l4"><a class="reference internal" href="rs.slaveOk.html">rs.slaveOk()</a></li><li class="toctree-l4"><a class="reference internal" href="rs.status.html">rs.status()</a></li><li class="toctree-l4"><a class="reference internal" href="rs.stepDown.html">rs.stepDown()</a></li><li class="toctree-l4"><a class="reference internal" href="rs.syncFrom.html">rs.syncFrom()</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="js-sharding.html">Sharding Methods</a><ul><li class="toctree-l4"><a class="reference internal" href="sh.addShard.html">sh.addShard()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.addShardTag.html">sh.addShardTag()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.addShardToZone.html">sh.addShardToZone()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.addTagRange.html">sh.addTagRange()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.disableBalancing.html">sh.disableBalancing()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.enableBalancing.html">sh.enableBalancing()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.disableAutoSplit.html">sh.disableAutoSplit</a></li><li class="toctree-l4"><a class="reference internal" href="sh.enableAutoSplit.html">sh.enableAutoSplit</a></li><li class="toctree-l4"><a class="reference internal" href="sh.enableSharding.html">sh.enableSharding()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.getBalancerHost.html">sh.getBalancerHost()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.getBalancerState.html">sh.getBalancerState()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.removeTagRange.html">sh.removeTagRange()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.removeRangeFromZone.html">sh.removeRangeFromZone()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.help.html">sh.help()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.isBalancerRunning.html">sh.isBalancerRunning()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.moveChunk.html">sh.moveChunk()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.removeShardTag.html">sh.removeShardTag()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.removeShardFromZone.html">sh.removeShardFromZone()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.setBalancerState.html">sh.setBalancerState()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.shardCollection.html">sh.shardCollection()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.splitAt.html">sh.splitAt()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.splitFind.html">sh.splitFind()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.startBalancer.html">sh.startBalancer()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.status.html">sh.status()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.stopBalancer.html">sh.stopBalancer()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.waitForBalancer.html">sh.waitForBalancer()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.waitForBalancerOff.html">sh.waitForBalancerOff()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.waitForPingChange.html">sh.waitForPingChange()</a></li><li class="toctree-l4"><a class="reference internal" href="sh.updateZoneKeyRange.html">sh.updateZoneKeyRange()</a></li><li class="toctree-l4"><a class="reference internal" href="convertShardKeyToHashed.html">convertShardKeyToHashed</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="js-free-monitoring.html">Free Monitoring Methods</a><ul><li class="toctree-l4"><a class="reference internal" href="db.disableFreeMonitoring.html">db.disableFreeMonitoring()</a></li><li class="toctree-l4"><a class="reference internal" href="db.enableFreeMonitoring.html">db.enableFreeMonitoring()</a></li><li class="toctree-l4"><a class="reference internal" href="db.getFreeMonitoringStatus.html">db.getFreeMonitoringStatus</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="js-constructor.html">Object Constructors and Methods</a><ul><li class="toctree-l4"><a class="reference internal" href="BulkWriteResult.html">BulkWriteResult()</a></li><li class="toctree-l4"><a class="reference internal" href="Date.html">Date()</a></li><li class="toctree-l4"><a class="reference internal" href="ObjectId.html">ObjectId</a></li><li class="toctree-l4"><a class="reference internal" href="ObjectId.getTimestamp.html">ObjectId.getTimestamp()</a></li><li class="toctree-l4"><a class="reference internal" href="ObjectId.toString.html">ObjectId.toString()</a></li><li class="toctree-l4"><a class="reference internal" href="ObjectId.valueOf.html">ObjectId.valueOf()</a></li><li class="toctree-l4"><a class="reference internal" href="UUID.html">UUID()</a></li><li class="toctree-l4"><a class="reference internal" href="WriteResult.html">WriteResult()</a></li><li class="toctree-l4"><a class="reference internal" href="WriteResult.hasWriteError.html">WriteResult.hasWriteError()</a></li><li class="toctree-l4"><a class="reference internal" href="WriteResult.hasWriteConcernError.html">WriteResult.hasWriteConcernError()</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="js-connection.html">Connection Methods</a><ul><li class="toctree-l4"><a class="reference internal" href="connect.html">connect()</a></li><li class="toctree-l4"><a class="reference internal" href="Mongo.html">Mongo()</a></li><li class="toctree-l4"><a class="reference internal" href="Mongo.getDB.html">Mongo.getDB()</a></li><li class="toctree-l4"><a class="reference internal" href="Mongo.getReadPrefMode.html">Mongo.getReadPrefMode()</a></li><li class="toctree-l4"><a class="reference internal" href="Mongo.getReadPrefTagSet.html">Mongo.getReadPrefTagSet()</a></li><li class="toctree-l4"><a class="reference internal" href="Mongo.isCausalConsistency.html">Mongo.isCausalConsistency()</a></li><li class="toctree-l4"><a class="reference internal" href="Mongo.setCausalConsistency.html">Mongo.setCausalConsistency()</a></li><li class="toctree-l4"><a class="reference internal" href="Mongo.setReadPref.html">Mongo.setReadPref()</a></li><li class="toctree-l4"><a class="reference internal" href="Mongo.setSlaveOk.html">Mongo.setSlaveOk()</a></li><li class="toctree-l4"><a class="reference internal" href="Mongo.startSession.html">Mongo.startSession()</a></li><li class="toctree-l4"><a class="reference internal" href="Mongo.watch.html">Mongo.watch()</a></li><li class="toctree-l4"><a class="reference internal" href="Session.html">Session</a><ul><li class="toctree-l5"><a class="reference internal" href="Session.abortTransaction.html">Session.abortTransaction()</a></li><li class="toctree-l5"><a class="reference internal" href="Session.commitTransaction.html">Session.commitTransaction()</a></li><li class="toctree-l5"><a class="reference internal" href="Session.startTransaction.html">Session.startTransaction()</a></li></ul></li><li class="toctree-l4"><a class="reference internal" href="SessionOptions.html">SessionOptions</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="js-native.html">Native Methods</a><ul><li class="toctree-l4"><a class="reference internal" href="cat.html">cat()</a></li><li class="toctree-l4"><a class="reference internal" href="cd.html">cd()</a></li><li class="toctree-l4"><a class="reference internal" href="copyDbpath.html">copyDbpath()</a></li><li class="toctree-l4"><a class="reference internal" href="getHostName.html">getHostName()</a></li><li class="toctree-l4"><a class="reference internal" href="getMemInfo.html">getMemInfo()</a></li><li class="toctree-l4"><a class="reference internal" href="hostname.html">hostname()</a></li><li class="toctree-l4"><a class="reference internal" href="isInteractive.html">isInteractive()</a></li><li class="toctree-l4"><a class="reference internal" href="listFiles.html">listFiles()</a></li><li class="toctree-l4"><a class="reference internal" href="load.html">load()</a></li><li class="toctree-l4"><a class="reference internal" href="ls.html">ls()</a></li><li class="toctree-l4"><a class="reference internal" href="md5sumFile.html">md5sumFile()</a></li><li class="toctree-l4"><a class="reference internal" href="mkdir.html">mkdir()</a></li><li class="toctree-l4"><a class="reference internal" href="pwd.html">pwd()</a></li><li class="toctree-l4"><a class="reference internal" href="quit.html">quit()</a></li><li class="toctree-l4"><a class="reference internal" href="removeFile.html">removeFile()</a></li><li class="toctree-l4"><a class="reference internal" href="resetDbpath.html">resetDbpath()</a></li><li class="toctree-l4"><a class="reference internal" href="sleep.html">sleep()</a></li><li class="toctree-l4"><a class="reference internal" href="setVerboseShell.html">setVerboseShell()</a></li><li class="toctree-l4"><a class="reference internal" href="version.html">version()</a></li><li class="toctree-l4"><a class="reference internal" href="isWindows.html">_isWindows()</a></li><li class="toctree-l4"><a class="reference internal" href="rand.html">_rand()</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="js-client-side-field-level-encryption.html">Client-Side Field Level Encryption Methods</a><ul><li class="toctree-l4"><a class="reference internal" href="getKeyVault.html">getKeyVault()</a></li><li class="toctree-l4"><a class="reference internal" href="KeyVault.createKey.html">KeyVault.createKey()</a></li><li class="toctree-l4"><a class="reference internal" href="KeyVault.deleteKey.html">KeyVault.deleteKey()</a></li><li class="toctree-l4"><a class="reference internal" href="KeyVault.getKey.html">KeyVault.getKey()</a></li><li class="toctree-l4"><a class="reference internal" href="KeyVault.getKeys.html">KeyVault.getKeys()</a></li><li class="toctree-l4"><a class="reference internal" href="KeyVault.addKeyAlternateName.html">KeyVault.addKeyAlternateName()</a></li><li class="toctree-l4"><a class="reference internal" href="KeyVault.removeKeyAlternateName.html">KeyVault.removeKeyAlternateName()</a></li><li class="toctree-l4"><a class="reference internal" href="KeyVault.getKeyByAltName.html">KeyVault.getKeyByAltName()</a></li><li class="toctree-l4"><a class="reference internal" href="getClientEncryption.html">getClientEncryption()</a></li><li class="toctree-l4"><a class="reference internal" href="ClientEncryption.encrypt.html">ClientEncryption.encrypt()</a></li><li class="toctree-l4"><a class="reference internal" href="ClientEncryption.decrypt.html">ClientEncryption.decrypt()</a></li></ul></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../program.html">MongoDB Package Components</a><ul><li class="toctree-l3"><a class="reference internal" href="../program/mongod.html"><code class="docutils literal"><span class="pre">mongod</span></code></a></li><li class="toctree-l3"><a class="reference internal" href="../program/mongos.html"><code class="docutils literal"><span class="pre">mongos</span></code></a></li><li class="toctree-l3"><a class="reference internal" href="../program/mongo.html"><code class="docutils literal"><span class="pre">mongo</span></code></a></li><li class="toctree-l3"><a class="reference internal" href="../program/mongod.exe.html"><code class="docutils literal"><span class="pre">mongod.exe</span></code></a></li><li class="toctree-l3"><a class="reference internal" href="../program/mongos.exe.html"><code class="docutils literal"><span class="pre">mongos.exe</span></code></a></li><li class="toctree-l3"><a class="reference internal" href="../program/mongodump.html"><code class="docutils literal"><span class="pre">mongodump</span></code></a></li><li class="toctree-l3"><a class="reference internal" href="../program/mongorestore.html"><code class="docutils literal"><span class="pre">mongorestore</span></code></a></li><li class="toctree-l3"><a class="reference internal" href="../program/bsondump.html"><code class="docutils literal"><span class="pre">bsondump</span></code></a></li><li class="toctree-l3"><a class="reference internal" href="../program/mongoimport.html"><code class="docutils literal"><span class="pre">mongoimport</span></code></a></li><li class="toctree-l3"><a class="reference internal" href="../program/mongoexport.html"><code class="docutils literal"><span class="pre">mongoexport</span></code></a></li><li class="toctree-l3"><a class="reference internal" href="../program/mongostat.html"><code class="docutils literal"><span class="pre">mongostat</span></code></a></li><li class="toctree-l3"><a class="reference internal" href="../program/mongotop.html"><code class="docutils literal"><span class="pre">mongotop</span></code></a></li><li class="toctree-l3"><a class="reference internal" href="../program/mongoreplay.html"><code class="docutils literal"><span class="pre">mongoreplay</span></code></a></li><li class="toctree-l3"><a class="reference internal" href="../program/mongoldap.html"><code class="docutils literal"><span class="pre">mongoldap</span></code></a></li><li class="toctree-l3"><a class="reference internal" href="../program/mongofiles.html"><code class="docutils literal"><span class="pre">mongofiles</span></code></a></li><li class="toctree-l3"><a class="reference internal" href="../program/install_compass.html"><code class="docutils literal"><span class="pre">install_compass</span></code></a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../configuration-options.html">Configuration File Options</a><ul><li class="toctree-l3"><a class="reference internal" href="../expansion-directives.html">Externally Sourced Configuration File Values</a></li><li class="toctree-l3"><a class="reference internal" href="../../tutorial/convert-command-line-options-to-yaml.html">Convert Command-Line Options to YAML</a></li><li class="toctree-l3"><a class="reference internal" href="../configuration-file-settings-command-line-options-mapping.html">Configuration File Settings and Command-Line Options Mapping</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../parameters.html">MongoDB Server Parameters</a></li><li class="toctree-l2"><a class="reference internal" href="../limits.html">MongoDB Limits and Thresholds</a></li><li class="toctree-l2"><a class="reference internal" href="../explain-results.html">Explain Results</a></li><li class="toctree-l2"><a class="reference internal" href="../system-collections.html">System Collections</a></li><li class="toctree-l2"><a class="reference internal" href="../connection-string.html">Connection String URI Format</a></li><li class="toctree-l2"><a class="reference internal" href="../collation.html">Collation</a><ul><li class="toctree-l3"><a class="reference internal" href="../collation-locales-defaults.html">Collation Locales and Default Parameters</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../mongodb-wire-protocol.html">MongoDB Wire Protocol</a></li><li class="toctree-l2"><a class="reference internal" href="../log-messages.html">Log Messages</a></li><li class="toctree-l2"><a class="reference internal" href="../exit-codes.html">Exit Codes and Statuses</a></li><li class="toctree-l2"><a class="reference internal" href="../glossary.html">Glossary</a></li><li class="toctree-l2"><a class="reference internal" href="../default-mongodb-port.html">Default MongoDB Port</a></li><li class="toctree-l2"><a class="reference internal" href="../server-sessions.html">Server Sessions</a></li></ul></li><li class="toctree-l1"><a class="reference internal" href="../../release-notes.html">Release Notes</a><ul><li class="toctree-l2"><a class="reference internal" href="../../release-notes/4.2.html">Release Notes for MongoDB 4.2</a><ul><li class="toctree-l3"><a class="reference internal" href="../../release-notes/4.2-compatibility.html">Compatibility Changes in MongoDB 4.2</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/4.2-upgrade-standalone.html">Upgrade a Standalone to 4.2</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/4.2-upgrade-replica-set.html">Upgrade a Replica Set to 4.2</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/4.2-upgrade-sharded-cluster.html">Upgrade a Sharded Cluster to 4.2</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/4.2-downgrade.html">Downgrade 4.2 to 4.0</a><ul><li class="toctree-l4"><a class="reference internal" href="../../release-notes/4.2-downgrade-standalone.html">Downgrade 4.2 Standalone to 4.0</a></li><li class="toctree-l4"><a class="reference internal" href="../../release-notes/4.2-downgrade-replica-set.html">Downgrade 4.2 Replica Set to 4.0</a></li><li class="toctree-l4"><a class="reference internal" href="../../release-notes/4.2-downgrade-sharded-cluster.html">Downgrade 4.2 Sharded Cluster to 4.0</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/4.2-changelog.html">4.2 Changelog</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../release-notes/4.0.html">Release Notes for MongoDB 4.0</a><ul><li class="toctree-l3"><a class="reference internal" href="../../release-notes/4.0-compatibility.html">Compatibility Changes in MongoDB 4.0</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/4.0-upgrade-standalone.html">Upgrade a Standalone to 4.0</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/4.0-upgrade-replica-set.html">Upgrade a Replica Set to 4.0</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/4.0-upgrade-sharded-cluster.html">Upgrade a Sharded Cluster to 4.0</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/4.0-downgrade-standalone.html">Downgrade 4.0 Standalone to 3.6</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/4.0-downgrade-replica-set.html">Downgrade 4.0 Replica Set to 3.6</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/4.0-downgrade-sharded-cluster.html">Downgrade 4.0 Sharded Cluster to 3.6</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/4.0-changelog.html">4.0 Changelog</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../release-notes/3.6.html">Release Notes for MongoDB 3.6</a><ul><li class="toctree-l3"><a class="reference internal" href="../../release-notes/3.6-changelog.html">3.6 Changelog</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/3.6-compatibility.html">Compatibility Changes in MongoDB 3.6</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/3.6-upgrade-standalone.html">Upgrade a Standalone to 3.6</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/3.6-upgrade-replica-set.html">Upgrade a Replica Set to 3.6</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/3.6-upgrade-sharded-cluster.html">Upgrade a Sharded Cluster to 3.6</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/3.6-downgrade-standalone.html">Downgrade 3.6 Standalone to 3.4</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/3.6-downgrade-replica-set.html">Downgrade 3.6 Replica Set to 3.4</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/3.6-downgrade-sharded-cluster.html">Downgrade 3.6 Sharded Cluster to 3.4</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../release-notes/3.4.html">Release Notes for MongoDB 3.4</a><ul><li class="toctree-l3"><a class="reference internal" href="../../release-notes/3.4-changelog.html">3.4 Changelog</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/3.4-compatibility.html">Compatibility Changes in MongoDB 3.4</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/3.4-upgrade-standalone.html">Upgrade a Standalone to 3.4</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/3.4-upgrade-replica-set.html">Upgrade a Replica Set to 3.4</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/3.4-upgrade-sharded-cluster.html">Upgrade a Sharded Cluster to 3.4</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/3.4-downgrade.html">Downgrade MongoDB 3.4 to 3.2</a><ul><li class="toctree-l4"><a class="reference internal" href="../../release-notes/3.4-downgrade-standalone.html">Downgrade 3.4 Standalone to 3.2</a></li><li class="toctree-l4"><a class="reference internal" href="../../release-notes/3.4-downgrade-replica-set.html">Downgrade 3.4 Replica Set to 3.2</a></li><li class="toctree-l4"><a class="reference internal" href="../../release-notes/3.4-downgrade-sharded-cluster.html">Downgrade 3.4 Sharded Cluster to 3.2</a></li></ul></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../release-notes/3.2.html">Release Notes for MongoDB 3.2</a><ul><li class="toctree-l3"><a class="reference internal" href="../../release-notes/3.2-changelog.html">3.2 Changelog</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/3.2-compatibility.html">Compatibility Changes in MongoDB 3.2</a><ul><li class="toctree-l4"><a class="reference internal" href="../../release-notes/3.2-javascript.html">JavaScript Changes in MongoDB 3.2</a></li></ul></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/3.2-upgrade.html">Upgrade MongoDB to 3.2</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/3.2-downgrade.html">Downgrade MongoDB from 3.2</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../release-notes/3.0.html">Release Notes for MongoDB 3.0</a><ul><li class="toctree-l3"><a class="reference internal" href="../../release-notes/3.0-changelog.html">3.0 Changelog</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/3.0-compatibility.html">Compatibility Changes in MongoDB 3.0</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/3.0-upgrade.html">Upgrade MongoDB to 3.0</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/3.0-scram.html">Upgrade to SCRAM</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/3.0-downgrade.html">Downgrade MongoDB from 3.0</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../release-notes/2.6.html">Release Notes for MongoDB 2.6</a><ul><li class="toctree-l3"><a class="reference internal" href="../../release-notes/2.6-changelog.html">2.6 Changelog</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/2.6-compatibility.html">Compatibility Changes in MongoDB 2.6</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/2.6-upgrade.html">Upgrade MongoDB to 2.6</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/2.6-upgrade-authorization.html">Upgrade User Authorization Data to 2.6 Format</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/2.6-downgrade.html">Downgrade MongoDB from 2.6</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../release-notes/2.4.html">Release Notes for MongoDB 2.4</a><ul><li class="toctree-l3"><a class="reference internal" href="../../release-notes/2.4-changelog.html">2.4 Changelog</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/2.4-javascript.html">JavaScript Changes in MongoDB 2.4</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/2.4-upgrade.html">Upgrade MongoDB to 2.4</a></li><li class="toctree-l3"><a class="reference internal" href="../../release-notes/2.4-index-types.html">Compatibility and Index Type Changes in MongoDB 2.4</a></li></ul></li><li class="toctree-l2"><a class="reference internal" href="../../release-notes/2.2.html">Release Notes for MongoDB 2.2</a></li><li class="toctree-l2"><a class="reference internal" href="../../release-notes/2.0.html">Release Notes for MongoDB 2.0</a></li><li class="toctree-l2"><a class="reference internal" href="../../release-notes/1.8.html">Release Notes for MongoDB 1.8</a></li><li class="toctree-l2"><a class="reference internal" href="../../release-notes/1.6.html">Release Notes for MongoDB 1.6</a></li><li class="toctree-l2"><a class="reference internal" href="../../release-notes/1.4.html">Release Notes for MongoDB 1.4</a></li><li class="toctree-l2"><a class="reference internal" href="../../release-notes/1.2.html">Release Notes for MongoDB 1.2.x</a></li><li class="toctree-l2"><a class="reference internal" href="../versioning.html">MongoDB Versioning</a></li></ul></li><li class="toctree-l1"><a class="reference internal" href="../../support.html">Technical Support</a></li></ul>


    </div>
  </div>
           
         </aside>

   </div>

    <div id="main-column" class="main-column">

    <span id="showNav" class="showNav">Navigation</span>

      
        <div class="document">
            <div class="documentwrapper"><div class="bodywrapper">
              <div class="body" data-pagename="reference/method/db.collection.update">
                   <a class="edit-link" href="https://github.com/mongodb/docs/blob/v4.2/source/reference/method/db.collection.update.txt" target="_blank" title="Edit reference/method/db.collection.update.txt on GitHub">
    
      <span class="icon-edit"></span>
    
  </a>
                

                
  <div class="bc">
    
      <ul>
          <li><a href="../../reference.html">Reference</a><span class="bcpoint"> > </span></li>
            
          <li><a href="../method.html"><code class="docutils literal"><span class="pre">mongo</span></code> Shell Methods</a><span class="bcpoint"> > </span></li>
            
          <li><a href="js-collection.html">Collection Methods</a><span class="bcpoint"> > </span></li>
            <li>db.collection.update()</li> 
      </ul>
    
    
  </div>
                
                  <div class="section" id="db-collection-update">
<h1>db.collection.update()<a class="headerlink" href="#db-collection-update" title="Permalink to this headline">¶</a></h1>
<div class="contents singlecol local topic" id="on-this-page">
<p class="topic-title first">On this page</p>
<ul class="simple">
<li><a class="reference internal" href="#definition" id="id1">Definition</a></li>
<li><a class="reference internal" href="#syntax" id="id2">Syntax</a></li>
<li><a class="reference internal" href="#access-control" id="id3">Access Control</a></li>
<li><a class="reference internal" href="#behavior" id="id4">Behavior</a></li>
<li><a class="reference internal" href="#examples" id="id5">Examples</a></li>
<li><a class="reference internal" href="#writeresult" id="id6">WriteResult</a></li>
</ul>
</div>
<div class="section" id="definition">
<h2>Definition<a class="headerlink" href="#definition" title="Permalink to this headline">¶</a></h2>
<dl class="method">
<dt id="db.collection.update">
<code class="descclassname">db.collection.</code><code class="descname">update</code><span class="sig-paren">(</span><em>query</em>, <em>update</em>, <em>options</em><span class="sig-paren">)</span><a class="headerlink" href="#db.collection.update" title="Permalink to this definition">¶</a></dt>
<dd><div class="important admonition">
<p class="first admonition-title"><code class="docutils literal"><span class="pre">mongo</span></code> Shell Method</p>
<p class="last">This page documents the <a class="reference internal" href="../program/mongo.html#bin.mongo" title="bin.mongo"><code class="xref mongodb mongodb-binary docutils literal"><span class="pre">mongo</span></code></a> shell method, and does
<em>not</em> refer to the MongoDB Node.js driver (or any other driver)
method. For corresponding MongoDB driver API, refer to your specific
<a class="reference external" href="https://docs.mongodb.com/ecosystem/drivers">MongoDB driver</a> documentation instead.</p>
</div>
<p>Modifies an existing document or documents in a collection. The
method can modify specific fields of an existing document or documents
or replace an existing document entirely, depending on the
<a class="reference internal" href="#update-parameter"><span class="std std-ref">update parameter</span></a>.</p>
<p>By default, the <a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> method updates a
<strong>single</strong> document. Include the option <a class="reference internal" href="#multi-parameter"><span class="std std-ref">multi: true</span></a>
to update all documents that match the query criteria.</p>
</dd></dl>

</div>
<div class="section" id="syntax">
<h2>Syntax<a class="headerlink" href="#syntax" title="Permalink to this headline">¶</a></h2>
<p>The <a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> method has the following form:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">collection</span><span class="p">.</span><span class="nx">update</span><span class="p">(</span>
   <span class="o">&lt;</span><span class="nx">query</span><span class="o">&gt;</span><span class="p">,</span>
   <span class="o">&lt;</span><span class="nx">update</span><span class="o">&gt;</span><span class="p">,</span>
   <span class="p">{</span>
     <span class="nx">upsert</span><span class="o">:</span> <span class="o">&lt;</span><span class="kr">boolean</span><span class="o">&gt;</span><span class="p">,</span>
     <span class="nx">multi</span><span class="o">:</span> <span class="o">&lt;</span><span class="kr">boolean</span><span class="o">&gt;</span><span class="p">,</span>
     <span class="nx">writeConcern</span><span class="o">:</span> <span class="o">&lt;</span><span class="nb">document</span><span class="o">&gt;</span><span class="p">,</span>
     <span class="nx">collation</span><span class="o">:</span> <span class="o">&lt;</span><span class="nb">document</span><span class="o">&gt;</span><span class="p">,</span>
     <span class="nx">arrayFilters</span><span class="o">:</span> <span class="p">[</span> <span class="o">&lt;</span><span class="nx">filterdocument1</span><span class="o">&gt;</span><span class="p">,</span> <span class="p">...</span> <span class="p">],</span>
     <span class="nx">hint</span><span class="o">:</span>  <span class="o">&lt;</span><span class="nb">document</span><span class="o">|</span><span class="nx">string</span><span class="o">&gt;</span>        <span class="c1">// Available starting in MongoDB 4.2</span>
   <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="parameters">
<h3>Parameters<a class="headerlink" href="#parameters" title="Permalink to this headline">¶</a></h3>
<p>The <a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> method takes the following
parameters:</p>
<table border="1" class="colwidths-given docutils">
<colgroup>
<col width="17%" />
<col width="17%" />
<col width="67%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Parameter</th>
<th class="head">Type</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><a class="reference internal" href="#update-query"><span class="std std-ref">query</span></a></td>
<td>document</td>
<td><p class="first" id="update-query">The selection criteria for the update. The same <a class="reference internal" href="../operator/query.html#query-selectors"><span class="std std-ref">query
selectors</span></a> as in the <a class="reference internal" href="db.collection.find.html#db.collection.find" title="db.collection.find()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">find()</span></code></a> method are available.</p>
<p class="last">When you execute an <a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">update()</span></code></a> with <code class="docutils literal"><span class="pre">upsert:</span>
<span class="pre">true</span></code> and the query matches no existing document, MongoDB will refuse
to insert a new document if the query specifies conditions on the
<code class="docutils literal"><span class="pre">_id</span></code> field using <a class="reference internal" href="../../core/document.html#document-dot-notation"><span class="std std-ref">dot notation</span></a>.</p>
</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#update-parameter"><span class="std std-ref">update</span></a></td>
<td>document or pipeline</td>
<td><p class="first" id="update-parameter">The modifications to apply. Can be one of the following:</p>
<table border="1" class="colwidths-given border-table docutils">
<colgroup>
<col width="33%" />
<col width="67%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><a class="reference internal" href="#update-method-update-document"><span class="std std-ref">Update document</span></a></td>
<td><p class="first last" id="update-method-update-document">Contains only <a class="reference internal" href="../operator/update.html#id1"><span class="std std-ref">update operator expressions</span></a>.</p>
</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#update-method-replacement-document"><span class="std std-ref">Replacement document</span></a></td>
<td><p class="first last" id="update-method-replacement-document">Contains only <code class="docutils literal"><span class="pre">&lt;field1&gt;:</span> <span class="pre">&lt;value1&gt;</span></code> pairs.</p>
</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#update-method-agg-pipeline"><span class="std std-ref">Aggregation pipeline</span></a>
(<em>Starting in MongoDB 4.2</em>)</td>
<td><p class="first" id="update-method-agg-pipeline">Contains only the following aggregation stages:</p>
<ul class="last simple">
<li><a class="reference internal" href="../operator/aggregation/addFields.html#pipe._S_addFields" title="$addFields"><code class="xref mongodb mongodb-pipeline docutils literal"><span class="pre">$addFields</span></code></a> and its alias <a class="reference internal" href="../operator/aggregation/set.html#pipe._S_set" title="$set"><code class="xref mongodb mongodb-pipeline docutils literal"><span class="pre">$set</span></code></a></li>
<li><a class="reference internal" href="../operator/aggregation/project.html#pipe._S_project" title="$project"><code class="xref mongodb mongodb-pipeline docutils literal"><span class="pre">$project</span></code></a> and its alias <a class="reference internal" href="../operator/aggregation/unset.html#pipe._S_unset" title="$unset"><code class="xref mongodb mongodb-pipeline docutils literal"><span class="pre">$unset</span></code></a></li>
<li><a class="reference internal" href="../operator/aggregation/replaceRoot.html#pipe._S_replaceRoot" title="$replaceRoot"><code class="xref mongodb mongodb-pipeline docutils literal"><span class="pre">$replaceRoot</span></code></a> and its alias <a class="reference internal" href="../operator/aggregation/replaceWith.html#pipe._S_replaceWith" title="$replaceWith"><code class="xref mongodb mongodb-pipeline docutils literal"><span class="pre">$replaceWith</span></code></a>.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="last">For details and examples, see <a class="reference internal" href="#update-method-examples"><span class="std std-ref">Examples</span></a>.</p>
</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#update-upsert"><span class="std std-ref">upsert</span></a></td>
<td>boolean</td>
<td><p class="first last" id="update-upsert">Optional. If set to <code class="docutils literal"><span class="pre">true</span></code>, creates a new document when no
document matches the query criteria. The default value is
<code class="docutils literal"><span class="pre">false</span></code>, which does <em>not</em> insert a new document when no match
is found.</p>
</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#update-multi"><span class="std std-ref">multi</span></a></td>
<td>boolean</td>
<td><p class="first last" id="update-multi">Optional. If set to <code class="docutils literal"><span class="pre">true</span></code>, updates multiple documents that
meet the <code class="docutils literal"><span class="pre">query</span></code> criteria. If set to <code class="docutils literal"><span class="pre">false</span></code>, updates one
document. The default value is <code class="docutils literal"><span class="pre">false</span></code>. For additional
information, see <a class="reference internal" href="#multi-parameter"><span class="std std-ref">Update Multiple Documents Examples</span></a>.</p>
</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#update-wc"><span class="std std-ref">writeConcern</span></a></td>
<td>document</td>
<td><p class="first" id="update-wc">Optional. A document expressing the <a class="reference internal" href="../write-concern.html"><span class="doc">write concern</span></a>. Omit to use the default write
concern <code class="docutils literal"><span class="pre">w:</span> <span class="pre">1</span></code>.</p>
<p>Do not explicitly set the write concern for the operation if run in
a transaction. To use write concern with transactions, see
<a class="reference internal" href="../../core/transactions.html#transactions-write-concern"><span class="std std-ref">Transactions and Write Concern</span></a>.</p>
<p class="last">For an example using <code class="docutils literal"><span class="pre">writeConcern</span></code>, see
<a class="reference internal" href="#example-update-write-concern"><span class="std std-ref">Override Default Write Concern</span></a>.</p>
</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#update-collation"><span class="std std-ref">collation</span></a></td>
<td>document</td>
<td><p class="first" id="update-collation">Optional.</p>
<p><a class="reference internal" href="../collation.html"><span class="doc">Collation</span></a> allows users to specify
language-specific rules for string comparison, such as rules for
lettercase and accent marks.</p>
<p>For an example using <code class="docutils literal"><span class="pre">collation</span></code>, see
<a class="reference internal" href="#example-update-collation"><span class="std std-ref">Specify Collation</span></a>.</p>
<div class="last versionadded">
<p><span class="versionmodified">New in version 3.4.</span></p>
</div>
</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#update-array-filters"><span class="std std-ref">arrayFilters</span></a></td>
<td>array</td>
<td><p class="first" id="update-array-filters">Optional. An array of filter documents that determine which array
elements to modify for an update operation on an array field.</p>
<p>In the <a class="reference internal" href="#update-parameter"><span class="std std-ref">update document</span></a>, use the
<a class="reference internal" href="../operator/update/positional-filtered.html#up._S_[&lt;identifier&gt;]" title="$[&lt;identifier&gt;]"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$[&lt;identifier&gt;]</span></code></a> to define an identifier to update
only those array elements that match the corresponding filter
document in the <code class="docutils literal"><span class="pre">arrayFilters</span></code>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">You cannot have an array filter document for an identifier if
the identifier is not included in the update document.</p>
</div>
<p>For examples, see <a class="reference internal" href="#update-arrayfilters"><span class="std std-ref">Specify arrayFilters for Array Update Operations</span></a>.</p>
<div class="last versionadded">
<p><span class="versionmodified">New in version 3.6.</span></p>
</div>
</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#update-hint"><span class="std std-ref">hint</span></a></td>
<td>Document or string</td>
<td><p class="first" id="update-hint">Optional. A document or string that specifies the <a class="reference internal" href="../../indexes.html"><span class="doc">index</span></a> to use to support the <a class="reference internal" href="#update-query"><span class="std std-ref">query predicate</span></a>.</p>
<p>The option can take an index specification document or the index
name string.</p>
<p>If you specify an index that does not exist, the operation
errors.</p>
<p>For an example, see <a class="reference internal" href="#ex-update-hint"><span class="std std-ref">Specify hint for Update Operations</span></a>.</p>
<div class="last versionadded">
<p><span class="versionmodified">New in version 4.2.</span></p>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="returns">
<h3>Returns<a class="headerlink" href="#returns" title="Permalink to this headline">¶</a></h3>
<p>The method returns a <a class="reference internal" href="#writeresults-update"><span class="std std-ref">WriteResult</span></a> document that contains
the status of the operation.</p>
</div>
</div>
<div class="section" id="access-control">
<h2>Access Control<a class="headerlink" href="#access-control" title="Permalink to this headline">¶</a></h2>
<p>On deployments running with <a class="reference internal" href="../configuration-options.html#security.authorization" title="security.authorization"><code class="xref mongodb mongodb-setting docutils literal"><span class="pre">authorization</span></code></a>, the
user must have access that includes the following privileges:</p>
<ul class="simple">
<li><a class="reference internal" href="../privilege-actions.html#update" title="update"><code class="xref mongodb mongodb-authaction docutils literal"><span class="pre">update</span></code></a> action on the specified collection(s).</li>
<li><a class="reference internal" href="../privilege-actions.html#find" title="find"><code class="xref mongodb mongodb-authaction docutils literal"><span class="pre">find</span></code></a> action on the specified collection(s).</li>
<li><a class="reference internal" href="../privilege-actions.html#insert" title="insert"><code class="xref mongodb mongodb-authaction docutils literal"><span class="pre">insert</span></code></a> action on the specified collection(s) if the
operation results in an upsert.</li>
</ul>
<p>The built-in role <a class="reference internal" href="../built-in-roles.html#readWrite" title="readWrite"><code class="xref mongodb mongodb-authrole docutils literal"><span class="pre">readWrite</span></code></a> provides the required
privileges.</p>
</div>
<div class="section" id="behavior">
<span id="update-behavior"></span><h2>Behavior<a class="headerlink" href="#behavior" title="Permalink to this headline">¶</a></h2>
<div class="section" id="sharded-collections">
<span id="update-sharded-collection"></span><h3>Sharded Collections<a class="headerlink" href="#sharded-collections" title="Permalink to this headline">¶</a></h3>
<p>To use <a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> with <code class="docutils literal"><span class="pre">multi:</span> <span class="pre">false</span></code> on a
sharded collection, you must include an exact match on the <code class="docutils literal"><span class="pre">_id</span></code>
field or target a single shard (such as by including the shard key).</p>
<p>When the <a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> performs update operations
(and not document replacement operations),
<a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> can target multiple shards.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="db.collection.findAndModify.html#db.collection.findAndModify" title="db.collection.findAndModify()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">findAndModify()</span></code></a></p>
</div>
<div class="section" id="replace-document-operations-on-a-sharded-collection">
<h4>Replace Document Operations on a Sharded Collection<a class="headerlink" href="#replace-document-operations-on-a-sharded-collection" title="Permalink to this headline">¶</a></h4>
<p>Starting in MongoDB 4.2, replace document operations attempt to target
a single shard, first by using the query filter. If the operation
cannot target a single shard by the query filter, it then attempts to target
by the replacement document.</p>
<p>In earlier versions, the operation attempts to target using the
replacement document.</p>
</div>
<div class="section" id="upsert-on-a-sharded-collection">
<h4><code class="docutils literal"><span class="pre">upsert</span></code> on a Sharded Collection<a class="headerlink" href="#upsert-on-a-sharded-collection" title="Permalink to this headline">¶</a></h4>
<p>For a <a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> operation that includes
<a class="reference internal" href="#update-upsert"><span class="std std-ref">upsert: true</span></a> and is on a sharded collection, you
must include the full shard key in the <code class="docutils literal"><span class="pre">filter</span></code>:</p>
<ul class="simple">
<li>For an update operation.</li>
<li>For a replace document operation (starting in MongoDB 4.2).</li>
</ul>
</div>
<div class="section" id="shard-key-modification">
<h4>Shard Key Modification<a class="headerlink" href="#shard-key-modification" title="Permalink to this headline">¶</a></h4>
<p>Starting in MongoDB 4.2, you can update a document’s shard key value
unless the shard key field is the immutable <code class="docutils literal"><span class="pre">_id</span></code> field. For details
on updating the shard key, see <a class="reference internal" href="../../core/sharding-shard-key.html#update-shard-key"><span class="std std-ref">Change a Document’s Shard Key Value</span></a>.</p>
<p>Before MongoDB 4.2, a document’s shard key field value is immutable.</p>
<p>To use <a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> to update the shard key:</p>
<ul class="simple">
<li>You must specify <code class="docutils literal"><span class="pre">multi:</span> <span class="pre">false</span></code>.</li>
</ul>
<ul class="simple">
<li>You <strong class="text-danger">must</strong> run on a <a class="reference internal" href="../program/mongos.html#bin.mongos" title="bin.mongos"><code class="xref mongodb mongodb-binary docutils literal"><span class="pre">mongos</span></code></a> either in a
<a class="reference internal" href="../../core/transactions.html"><span class="doc">transaction</span></a> or as a <a class="reference internal" href="../../core/retryable-writes.html"><span class="doc">retryable
write</span></a>. Do <strong class="text-danger">not</strong> issue the operation
directly on the shard.</li>
<li>You <strong class="text-danger">must</strong> include an equality condition on the full shard
key in the query filter. For example, if a collection <code class="docutils literal"><span class="pre">messages</span></code>
uses <code class="docutils literal"><span class="pre">{</span> <span class="pre">country</span> <span class="pre">:</span> <span class="pre">1,</span> <span class="pre">userid</span> <span class="pre">:</span> <span class="pre">1</span> <span class="pre">}</span></code> as the shard key, to update
the shard key for a document, you must include <code class="docutils literal"><span class="pre">country:</span> <span class="pre">&lt;value&gt;,</span>
<span class="pre">userid:</span> <span class="pre">&lt;value&gt;</span></code> in the query filter. You can include additional
fields in the query as appropriate.</li>
</ul>
</div>
</div>
<div class="section" id="transactions">
<h3>Transactions<a class="headerlink" href="#transactions" title="Permalink to this headline">¶</a></h3>
<p><a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> can be used inside <a class="reference internal" href="../../core/transactions.html"><span class="doc">multi-document transactions</span></a>.</p>
<div class="admonition important">
<p class="first admonition-title">Important</p>
<p>In most cases, multi-document transaction incurs a greater
performance cost over single document writes, and the
availability of multi-document transactions should not be a
replacement for effective schema design. For many scenarios, the
<a class="reference internal" href="../../core/data-model-design.html#data-modeling-embedding"><span class="std std-ref">denormalized data model (embedded documents and arrays)</span></a> will continue to be optimal for your
data and use cases. That is, for many scenarios, modeling your data
appropriately will minimize the need for multi-document
transactions.</p>
<p class="last">For additional transactions usage considerations
(such as runtime limit and oplog size limit), see also
<a class="reference internal" href="../../core/transactions-production-consideration.html"><span class="doc">Production Considerations</span></a>.</p>
</div>
<div class="section" id="existing-collections-and-transactions">
<h4>Existing Collections and Transactions<a class="headerlink" href="#existing-collections-and-transactions" title="Permalink to this headline">¶</a></h4>
<p>Inside a transaction, you can specify read/write operations on existing
collections. If the <a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> results in an
upsert, the collection must already exist.</p>
<p>If the operation results in an upsert, the collection must already exist.</p>
</div>
<div class="section" id="write-concerns-and-transactions">
<h4>Write Concerns and Transactions<a class="headerlink" href="#write-concerns-and-transactions" title="Permalink to this headline">¶</a></h4>
<p>Do not explicitly set the write concern for the operation if run in
a transaction. To use write concern with transactions, see
<a class="reference internal" href="../../core/transactions.html#transactions-write-concern"><span class="std std-ref">Transactions and Write Concern</span></a>.</p>
</div>
</div>
</div>
<div class="section" id="examples">
<span id="update-behavior-replacement-document"></span><span id="example-update-replace-fields"></span><span id="example-update-specific-fields"></span><span id="multi-parameter"></span><span id="update-behavior-operator-expressions-document"></span><span id="update-method-examples"></span><h2>Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h2>
<div class="docutils container">
<div class="tabs" >
  <ul class="tab-strip tab-strip--singleton" role="tablist">
    <li class="tab-strip__element" data-tabid="opexpr" role="tab" aria-selected="true">Use Update Operator Expressions ($inc, $set)</li>
    <li class="tab-strip__element" data-tabid="pushelementsexistingarray" role="tab" aria-selected="false">Push Elements to Existing Array</li>
    <li class="tab-strip__element" data-tabid="removefields" role="tab" aria-selected="false">Remove Fields ($unset)</li>
    <li class="tab-strip__element" data-tabid="replacedoc" role="tab" aria-selected="false">Replace Entire Document</li>
    <li class="tab-strip__element" data-tabid="updatemultiple" role="tab" aria-selected="false">Update Multiple Documents</li>
  </ul>
  <div class="tabs__content" role="tabpanel">
    <div class="tabpanel-opexpr" data-tabid="opexpr"><p>From the <a class="reference internal" href="../program/mongo.html#bin.mongo" title="bin.mongo"><code class="xref mongodb mongodb-binary docutils literal"><span class="pre">mongo</span></code></a> shell, create a <code class="docutils literal"><span class="pre">books</span></code> collection which
contains the following documents. This command first removes all
previously existing documents from the <code class="docutils literal"><span class="pre">books</span></code> collection:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">books</span><span class="p">.</span><span class="nx">remove</span><span class="p">({});</span>

<span class="nx">db</span><span class="p">.</span><span class="nx">books</span><span class="p">.</span><span class="nx">insertMany</span><span class="p">([</span>
  <span class="p">{</span>
    <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span>
    <span class="s2">&quot;item&quot;</span> <span class="o">:</span> <span class="s2">&quot;TBD&quot;</span><span class="p">,</span>
    <span class="s2">&quot;stock&quot;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">,</span>
    <span class="s2">&quot;info&quot;</span> <span class="o">:</span> <span class="p">{</span> <span class="s2">&quot;publisher&quot;</span> <span class="o">:</span> <span class="s2">&quot;1111&quot;</span><span class="p">,</span> <span class="s2">&quot;pages&quot;</span> <span class="o">:</span> <span class="mi">430</span> <span class="p">},</span>
    <span class="s2">&quot;tags&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;technology&quot;</span><span class="p">,</span> <span class="s2">&quot;computer&quot;</span> <span class="p">],</span>
    <span class="s2">&quot;ratings&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;ijk&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">4</span> <span class="p">},</span> <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;lmn&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">5</span> <span class="p">}</span> <span class="p">],</span>
    <span class="s2">&quot;reorder&quot;</span> <span class="o">:</span> <span class="kc">false</span>
   <span class="p">},</span>
   <span class="p">{</span>
    <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">2</span><span class="p">,</span>
    <span class="s2">&quot;item&quot;</span> <span class="o">:</span> <span class="s2">&quot;XYZ123&quot;</span><span class="p">,</span>
    <span class="s2">&quot;stock&quot;</span> <span class="o">:</span> <span class="mi">15</span><span class="p">,</span>
    <span class="s2">&quot;info&quot;</span> <span class="o">:</span> <span class="p">{</span> <span class="s2">&quot;publisher&quot;</span> <span class="o">:</span> <span class="s2">&quot;5555&quot;</span><span class="p">,</span> <span class="s2">&quot;pages&quot;</span> <span class="o">:</span> <span class="mi">150</span> <span class="p">},</span>
    <span class="s2">&quot;tags&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="p">],</span>
    <span class="s2">&quot;ratings&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;xyz&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">5</span> <span class="p">}</span> <span class="p">],</span>
    <span class="s2">&quot;reorder&quot;</span> <span class="o">:</span> <span class="kc">false</span>
   <span class="p">}</span>
<span class="p">]);</span>
</pre></div>
</div>
</div>
<p>If the <code class="docutils literal"><span class="pre">&lt;update&gt;</span></code> document contains <a class="reference internal" href="../operator/update.html#id1"><span class="std std-ref">update operator</span></a> modifiers, such as those using the
<a class="reference internal" href="../operator/update/set.html#up._S_set" title="$set"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$set</span></code></a> modifier, then:</p>
<ul class="simple">
<li>The <code class="docutils literal"><span class="pre">&lt;update&gt;</span></code> document must contain <em>only</em>
<a class="reference internal" href="../operator/update.html#id1"><span class="std std-ref">update operator</span></a> expressions.</li>
<li>The <a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> method updates only the
corresponding fields in the document.<ul>
<li>To update an embedded document or an array as a whole,
specify the replacement value for the field.</li>
<li>To update particular fields in an embedded document or in
an array, use <a class="reference internal" href="../../core/document.html#document-dot-notation"><span class="std std-ref">dot notation</span></a>
to specify the field.</li>
</ul>
</li>
</ul>
<p>You can use the web shell below to insert the sample
documents and execute the example update operation:</p>
<iframe class="mws-root" allowfullscreen sandbox="allow-scripts allow-same-origin" width=100% height=320 src="https://mws.mongodb.com/?version=4.2"></iframe><div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">books</span><span class="p">.</span><span class="nx">update</span><span class="p">(</span>
   <span class="p">{</span> <span class="nx">_id</span><span class="o">:</span> <span class="mi">1</span> <span class="p">},</span>
   <span class="p">{</span>
     <span class="nx">$inc</span><span class="o">:</span> <span class="p">{</span> <span class="nx">stock</span><span class="o">:</span> <span class="mi">5</span> <span class="p">},</span>
     <span class="nx">$set</span><span class="o">:</span> <span class="p">{</span>
       <span class="nx">item</span><span class="o">:</span> <span class="s2">&quot;ABC123&quot;</span><span class="p">,</span>
       <span class="s2">&quot;info.publisher&quot;</span><span class="o">:</span> <span class="s2">&quot;2222&quot;</span><span class="p">,</span>
       <span class="nx">tags</span><span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;software&quot;</span> <span class="p">],</span>
       <span class="s2">&quot;ratings.1&quot;</span><span class="o">:</span> <span class="p">{</span> <span class="nx">by</span><span class="o">:</span> <span class="s2">&quot;xyz&quot;</span><span class="p">,</span> <span class="nx">rating</span><span class="o">:</span> <span class="mi">3</span> <span class="p">}</span>
     <span class="p">}</span>
   <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<p>In this operation:</p>
<ul class="simple">
<li>The <code class="docutils literal"><span class="pre">&lt;query&gt;</span></code> parameter of <code class="docutils literal"><span class="pre">{</span> <span class="pre">_id:</span> <span class="pre">1</span> <span class="pre">}</span></code> specifies which
document to update,</li>
<li>the <a class="reference internal" href="../operator/update/inc.html#up._S_inc" title="$inc"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$inc</span></code></a> operator increments the <code class="docutils literal"><span class="pre">stock</span></code> field,
and</li>
<li>the <a class="reference internal" href="../operator/update/set.html#up._S_set" title="$set"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$set</span></code></a> operator replaces the value of the<ul>
<li><code class="docutils literal"><span class="pre">item</span></code> field,</li>
<li><code class="docutils literal"><span class="pre">publisher</span></code> field in the <code class="docutils literal"><span class="pre">info</span></code> embedded document,</li>
<li><code class="docutils literal"><span class="pre">tags</span></code> field, and</li>
<li>second element in the <code class="docutils literal"><span class="pre">ratings</span></code> array.</li>
</ul>
</li>
</ul>
<p>The updated document is the following:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="p">{</span>
<span class="hll">  <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span>
</span>  <span class="s2">&quot;item&quot;</span> <span class="o">:</span> <span class="s2">&quot;ABC123&quot;</span><span class="p">,</span>
<span class="hll">  <span class="s2">&quot;stock&quot;</span> <span class="o">:</span> <span class="mi">5</span><span class="p">,</span>
</span><span class="hll">  <span class="s2">&quot;info&quot;</span> <span class="o">:</span> <span class="p">{</span> <span class="s2">&quot;publisher&quot;</span> <span class="o">:</span> <span class="s2">&quot;2222&quot;</span><span class="p">,</span> <span class="s2">&quot;pages&quot;</span> <span class="o">:</span> <span class="mi">430</span> <span class="p">},</span>
</span><span class="hll">  <span class="s2">&quot;tags&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;software&quot;</span> <span class="p">],</span>
</span>  <span class="s2">&quot;ratings&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;ijk&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">4</span> <span class="p">},</span> <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;xyz&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">3</span> <span class="p">}</span> <span class="p">],</span>
  <span class="s2">&quot;reorder&quot;</span> <span class="o">:</span> <span class="kc">false</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<p>This operation corresponds to the following SQL statement:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-sql"><div class="highlight"><pre><span></span><span class="k">UPDATE</span> <span class="n">books</span>
<span class="k">SET</span>    <span class="n">stock</span> <span class="o">=</span> <span class="n">stock</span> <span class="o">+</span> <span class="mi">5</span>
       <span class="n">item</span> <span class="o">=</span> <span class="ss">&quot;ABC123&quot;</span>
       <span class="n">publisher</span> <span class="o">=</span> <span class="mi">2222</span>
       <span class="n">pages</span> <span class="o">=</span> <span class="mi">430</span>
       <span class="n">tags</span> <span class="o">=</span> <span class="ss">&quot;software&quot;</span>
       <span class="n">rating_authors</span> <span class="o">=</span> <span class="ss">&quot;ijk,xyz&quot;</span>
       <span class="n">rating_values</span> <span class="o">=</span> <span class="ss">&quot;4,3&quot;</span>
<span class="k">WHERE</span>  <span class="n">_id</span> <span class="o">=</span> <span class="mi">1</span>
</pre></div>
</div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If the <code class="docutils literal"><span class="pre">query</span></code> parameter had matched multiple documents,
this operation would only update one matching document. To
update multiple documents, you must set the <code class="docutils literal"><span class="pre">multi</span></code> option
to <code class="docutils literal"><span class="pre">true</span></code>.</p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="../operator/update/set.html#up._S_set" title="$set"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$set</span></code></a>, <a class="reference internal" href="../operator/update/inc.html#up._S_inc" title="$inc"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$inc</span></code></a>,
<a class="reference internal" href="../operator/update.html"><span class="doc">Update Operators</span></a>,
<a class="reference internal" href="../../core/document.html#document-dot-notation"><span class="std std-ref">dot notation</span></a></p>
</div>
</div>
<div class="tabpanel-pushelementsexistingarray" data-tabid="pushelementsexistingarray"><p>From the <a class="reference internal" href="../program/mongo.html#bin.mongo" title="bin.mongo"><code class="xref mongodb mongodb-binary docutils literal"><span class="pre">mongo</span></code></a> shell, create a <code class="docutils literal"><span class="pre">books</span></code> collection which
contains the following documents. This command first removes all
previously existing documents from the <code class="docutils literal"><span class="pre">books</span></code> collection:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">books</span><span class="p">.</span><span class="nx">remove</span><span class="p">({});</span>

<span class="nx">db</span><span class="p">.</span><span class="nx">books</span><span class="p">.</span><span class="nx">insertMany</span><span class="p">([</span>
  <span class="p">{</span>
    <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span>
    <span class="s2">&quot;item&quot;</span> <span class="o">:</span> <span class="s2">&quot;TBD&quot;</span><span class="p">,</span>
    <span class="s2">&quot;stock&quot;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">,</span>
    <span class="s2">&quot;info&quot;</span> <span class="o">:</span> <span class="p">{</span> <span class="s2">&quot;publisher&quot;</span> <span class="o">:</span> <span class="s2">&quot;1111&quot;</span><span class="p">,</span> <span class="s2">&quot;pages&quot;</span> <span class="o">:</span> <span class="mi">430</span> <span class="p">},</span>
    <span class="s2">&quot;tags&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;technology&quot;</span><span class="p">,</span> <span class="s2">&quot;computer&quot;</span> <span class="p">],</span>
    <span class="s2">&quot;ratings&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;ijk&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">4</span> <span class="p">},</span> <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;lmn&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">5</span> <span class="p">}</span> <span class="p">],</span>
    <span class="s2">&quot;reorder&quot;</span> <span class="o">:</span> <span class="kc">false</span>
   <span class="p">},</span>
   <span class="p">{</span>
    <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">2</span><span class="p">,</span>
    <span class="s2">&quot;item&quot;</span> <span class="o">:</span> <span class="s2">&quot;XYZ123&quot;</span><span class="p">,</span>
    <span class="s2">&quot;stock&quot;</span> <span class="o">:</span> <span class="mi">15</span><span class="p">,</span>
    <span class="s2">&quot;info&quot;</span> <span class="o">:</span> <span class="p">{</span> <span class="s2">&quot;publisher&quot;</span> <span class="o">:</span> <span class="s2">&quot;5555&quot;</span><span class="p">,</span> <span class="s2">&quot;pages&quot;</span> <span class="o">:</span> <span class="mi">150</span> <span class="p">},</span>
    <span class="s2">&quot;tags&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="p">],</span>
    <span class="s2">&quot;ratings&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;xyz&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">5</span> <span class="p">}</span> <span class="p">],</span>
    <span class="s2">&quot;reorder&quot;</span> <span class="o">:</span> <span class="kc">false</span>
   <span class="p">}</span>
<span class="p">]);</span>
</pre></div>
</div>
</div>
<p>The following operation uses the <a class="reference internal" href="../operator/update/push.html#up._S_push" title="$push"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$push</span></code></a> update
operator to append a new object to the <code class="docutils literal"><span class="pre">ratings</span></code> array.</p>
<p>You can use the web shell below to insert the sample
documents and execute the example update operation:</p>
<iframe class="mws-root" allowfullscreen sandbox="allow-scripts allow-same-origin" width=100% height=320 src="https://mws.mongodb.com/?version=4.2"></iframe><div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">books</span><span class="p">.</span><span class="nx">update</span><span class="p">(</span>
   <span class="p">{</span> <span class="nx">_id</span><span class="o">:</span> <span class="mi">2</span> <span class="p">},</span>
   <span class="p">{</span>
     <span class="nx">$push</span><span class="o">:</span> <span class="p">{</span> <span class="nx">ratings</span><span class="o">:</span> <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;jkl&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">2</span> <span class="p">}</span> <span class="p">}</span>
   <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<p>The updated document is the following:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="p">{</span>
  <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">2</span><span class="p">,</span>
  <span class="s2">&quot;item&quot;</span> <span class="o">:</span> <span class="s2">&quot;XYZ123&quot;</span><span class="p">,</span>
  <span class="s2">&quot;stock&quot;</span> <span class="o">:</span> <span class="mi">15</span><span class="p">,</span>
  <span class="s2">&quot;info&quot;</span> <span class="o">:</span> <span class="p">{</span>
   <span class="s2">&quot;publisher&quot;</span> <span class="o">:</span> <span class="s2">&quot;5555&quot;</span><span class="p">,</span>
   <span class="s2">&quot;pages&quot;</span> <span class="o">:</span> <span class="mi">150</span>
  <span class="p">},</span>
  <span class="s2">&quot;tags&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="p">],</span>
  <span class="s2">&quot;ratings&quot;</span> <span class="o">:</span> <span class="p">[</span>
   <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;xyz&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">5</span> <span class="p">},</span>
<span class="hll">   <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;jkl&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">2</span> <span class="p">}</span>
</span>  <span class="p">],</span>
  <span class="s2">&quot;reorder&quot;</span> <span class="o">:</span> <span class="kc">false</span>
 <span class="p">}</span>
</pre></div>
</div>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="../operator/update/push.html#up._S_push" title="$push"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$push</span></code></a></p>
</div>
</div>
<div class="tabpanel-removefields" data-tabid="removefields"><p>From the <a class="reference internal" href="../program/mongo.html#bin.mongo" title="bin.mongo"><code class="xref mongodb mongodb-binary docutils literal"><span class="pre">mongo</span></code></a> shell, create a <code class="docutils literal"><span class="pre">books</span></code> collection which
contains the following documents. This command first removes all
previously existing documents from the <code class="docutils literal"><span class="pre">books</span></code> collection:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">books</span><span class="p">.</span><span class="nx">remove</span><span class="p">({});</span>

<span class="nx">db</span><span class="p">.</span><span class="nx">books</span><span class="p">.</span><span class="nx">insertMany</span><span class="p">([</span>
  <span class="p">{</span>
    <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span>
    <span class="s2">&quot;item&quot;</span> <span class="o">:</span> <span class="s2">&quot;TBD&quot;</span><span class="p">,</span>
    <span class="s2">&quot;stock&quot;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">,</span>
    <span class="s2">&quot;info&quot;</span> <span class="o">:</span> <span class="p">{</span> <span class="s2">&quot;publisher&quot;</span> <span class="o">:</span> <span class="s2">&quot;1111&quot;</span><span class="p">,</span> <span class="s2">&quot;pages&quot;</span> <span class="o">:</span> <span class="mi">430</span> <span class="p">},</span>
    <span class="s2">&quot;tags&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;technology&quot;</span><span class="p">,</span> <span class="s2">&quot;computer&quot;</span> <span class="p">],</span>
    <span class="s2">&quot;ratings&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;ijk&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">4</span> <span class="p">},</span> <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;lmn&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">5</span> <span class="p">}</span> <span class="p">],</span>
    <span class="s2">&quot;reorder&quot;</span> <span class="o">:</span> <span class="kc">false</span>
   <span class="p">},</span>
   <span class="p">{</span>
    <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">2</span><span class="p">,</span>
    <span class="s2">&quot;item&quot;</span> <span class="o">:</span> <span class="s2">&quot;XYZ123&quot;</span><span class="p">,</span>
    <span class="s2">&quot;stock&quot;</span> <span class="o">:</span> <span class="mi">15</span><span class="p">,</span>
    <span class="s2">&quot;info&quot;</span> <span class="o">:</span> <span class="p">{</span> <span class="s2">&quot;publisher&quot;</span> <span class="o">:</span> <span class="s2">&quot;5555&quot;</span><span class="p">,</span> <span class="s2">&quot;pages&quot;</span> <span class="o">:</span> <span class="mi">150</span> <span class="p">},</span>
    <span class="s2">&quot;tags&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="p">],</span>
    <span class="s2">&quot;ratings&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;xyz&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">5</span> <span class="p">}</span> <span class="p">],</span>
    <span class="s2">&quot;reorder&quot;</span> <span class="o">:</span> <span class="kc">false</span>
   <span class="p">}</span>
<span class="p">]);</span>
</pre></div>
</div>
</div>
<p>The following operation uses the <a class="reference internal" href="../operator/update/unset.html#up._S_unset" title="$unset"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$unset</span></code></a> operator to remove
the <code class="docutils literal"><span class="pre">tags</span></code> field from the document with <code class="docutils literal"><span class="pre">{</span> <span class="pre">_id:</span> <span class="pre">1</span> <span class="pre">}</span></code>.</p>
<p>You can use the web shell below to insert the sample
documents and execute the example update operation:</p>
<iframe class="mws-root" allowfullscreen sandbox="allow-scripts allow-same-origin" width=100% height=320 src="https://mws.mongodb.com/?version=4.2"></iframe><div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">books</span><span class="p">.</span><span class="nx">update</span><span class="p">(</span> <span class="p">{</span> <span class="nx">_id</span><span class="o">:</span> <span class="mi">1</span> <span class="p">},</span> <span class="p">{</span> <span class="nx">$unset</span><span class="o">:</span> <span class="p">{</span> <span class="nx">tags</span><span class="o">:</span> <span class="mi">1</span> <span class="p">}</span> <span class="p">}</span> <span class="p">)</span>
</pre></div>
</div>
</div>
<p>The updated document is the following:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="p">{</span>
  <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span>
  <span class="s2">&quot;item&quot;</span> <span class="o">:</span> <span class="s2">&quot;TBD&quot;</span><span class="p">,</span>
  <span class="s2">&quot;stock&quot;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">,</span>
  <span class="s2">&quot;info&quot;</span> <span class="o">:</span> <span class="p">{</span>
   <span class="s2">&quot;publisher&quot;</span> <span class="o">:</span> <span class="s2">&quot;1111&quot;</span><span class="p">,</span>
   <span class="s2">&quot;pages&quot;</span> <span class="o">:</span> <span class="mi">430</span>
  <span class="p">},</span>
  <span class="s2">&quot;ratings&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;ijk&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">4</span> <span class="p">},</span> <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;lmn&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">5</span> <span class="p">}</span> <span class="p">],</span>
  <span class="s2">&quot;reorder&quot;</span> <span class="o">:</span> <span class="kc">false</span>
 <span class="p">}</span>
</pre></div>
</div>
</div>
<p>There is not a direct SQL equivalent to <a class="reference internal" href="../operator/update/unset.html#up._S_unset" title="$unset"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$unset</span></code></a>,
however <a class="reference internal" href="../operator/update/unset.html#up._S_unset" title="$unset"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$unset</span></code></a> is similar to the following SQL
command which removes the <code class="docutils literal"><span class="pre">tags</span></code> field from the <code class="docutils literal"><span class="pre">books</span></code>
table:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-sql"><div class="highlight"><pre><span></span><span class="k">ALTER</span> <span class="k">TABLE</span> <span class="n">books</span>
<span class="k">DROP</span> <span class="k">COLUMN</span> <span class="n">tags</span>
</pre></div>
</div>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="../operator/update/unset.html#up._S_unset" title="$unset"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$unset</span></code></a>, <a class="reference internal" href="../operator/update/rename.html#up._S_rename" title="$rename"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$rename</span></code></a>, <a class="reference internal" href="../operator/update.html"><span class="doc">Update Operators</span></a></p>
</div>
</div>
<div class="tabpanel-replacedoc" data-tabid="replacedoc"><p>From the <a class="reference internal" href="../program/mongo.html#bin.mongo" title="bin.mongo"><code class="xref mongodb mongodb-binary docutils literal"><span class="pre">mongo</span></code></a> shell, create a <code class="docutils literal"><span class="pre">books</span></code> collection which
contains the following documents. This command first removes all
previously existing documents from the <code class="docutils literal"><span class="pre">books</span></code> collection:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">books</span><span class="p">.</span><span class="nx">remove</span><span class="p">({});</span>

<span class="nx">db</span><span class="p">.</span><span class="nx">books</span><span class="p">.</span><span class="nx">insertMany</span><span class="p">([</span>
  <span class="p">{</span>
    <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span>
    <span class="s2">&quot;item&quot;</span> <span class="o">:</span> <span class="s2">&quot;TBD&quot;</span><span class="p">,</span>
    <span class="s2">&quot;stock&quot;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">,</span>
    <span class="s2">&quot;info&quot;</span> <span class="o">:</span> <span class="p">{</span> <span class="s2">&quot;publisher&quot;</span> <span class="o">:</span> <span class="s2">&quot;1111&quot;</span><span class="p">,</span> <span class="s2">&quot;pages&quot;</span> <span class="o">:</span> <span class="mi">430</span> <span class="p">},</span>
    <span class="s2">&quot;tags&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;technology&quot;</span><span class="p">,</span> <span class="s2">&quot;computer&quot;</span> <span class="p">],</span>
    <span class="s2">&quot;ratings&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;ijk&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">4</span> <span class="p">},</span> <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;lmn&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">5</span> <span class="p">}</span> <span class="p">],</span>
    <span class="s2">&quot;reorder&quot;</span> <span class="o">:</span> <span class="kc">false</span>
   <span class="p">},</span>
   <span class="p">{</span>
    <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">2</span><span class="p">,</span>
    <span class="s2">&quot;item&quot;</span> <span class="o">:</span> <span class="s2">&quot;XYZ123&quot;</span><span class="p">,</span>
    <span class="s2">&quot;stock&quot;</span> <span class="o">:</span> <span class="mi">15</span><span class="p">,</span>
    <span class="s2">&quot;info&quot;</span> <span class="o">:</span> <span class="p">{</span> <span class="s2">&quot;publisher&quot;</span> <span class="o">:</span> <span class="s2">&quot;5555&quot;</span><span class="p">,</span> <span class="s2">&quot;pages&quot;</span> <span class="o">:</span> <span class="mi">150</span> <span class="p">},</span>
    <span class="s2">&quot;tags&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="p">],</span>
    <span class="s2">&quot;ratings&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;xyz&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">5</span> <span class="p">}</span> <span class="p">],</span>
    <span class="s2">&quot;reorder&quot;</span> <span class="o">:</span> <span class="kc">false</span>
   <span class="p">}</span>
<span class="p">]);</span>
</pre></div>
</div>
</div>
<p>If the <code class="docutils literal"><span class="pre">&lt;update&gt;</span></code> document contains <em>only</em> <code class="docutils literal"><span class="pre">field:value</span></code>
expressions, then:</p>
<ul class="simple">
<li>The <a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> method <em>replaces</em> the matching
document with the <code class="docutils literal"><span class="pre">&lt;update&gt;</span></code> document. The
<a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> method <em>does not</em> replace the
<code class="docutils literal"><span class="pre">_id</span></code> value.</li>
<li><a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> <em>cannot</em> update multiple
documents.</li>
</ul>
<p>The following operation passes an <code class="docutils literal"><span class="pre">&lt;update&gt;</span></code> document that contains
only field and value pairs. The <code class="docutils literal"><span class="pre">&lt;update&gt;</span></code> document completely
replaces the original document except for the <code class="docutils literal"><span class="pre">_id</span></code> field.</p>
<p>You can use the web shell below to insert the sample
documents and execute the example update operation:</p>
<iframe class="mws-root" allowfullscreen sandbox="allow-scripts allow-same-origin" width=100% height=320 src="https://mws.mongodb.com/?version=4.2"></iframe><div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">books</span><span class="p">.</span><span class="nx">update</span><span class="p">(</span>
   <span class="p">{</span> <span class="nx">_id</span><span class="o">:</span> <span class="mi">2</span> <span class="p">},</span>
   <span class="p">{</span>
     <span class="nx">item</span><span class="o">:</span> <span class="s2">&quot;XYZ123&quot;</span><span class="p">,</span>
     <span class="nx">stock</span><span class="o">:</span> <span class="mi">10</span><span class="p">,</span>
     <span class="nx">info</span><span class="o">:</span> <span class="p">{</span> <span class="nx">publisher</span><span class="o">:</span> <span class="s2">&quot;2255&quot;</span><span class="p">,</span> <span class="nx">pages</span><span class="o">:</span> <span class="mi">150</span> <span class="p">},</span>
     <span class="nx">tags</span><span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;baking&quot;</span><span class="p">,</span> <span class="s2">&quot;cooking&quot;</span> <span class="p">]</span>
   <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<p>The updated document contains <em>only</em> the fields from the
replacement document and the <code class="docutils literal"><span class="pre">_id</span></code> field. As such, the fields
<code class="docutils literal"><span class="pre">ratings</span></code> and <code class="docutils literal"><span class="pre">reorder</span></code> no longer exist in the updated
document since the fields were not in the replacement document.</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="p">{</span>
   <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">2</span><span class="p">,</span>
   <span class="s2">&quot;item&quot;</span> <span class="o">:</span> <span class="s2">&quot;XYZ123&quot;</span><span class="p">,</span>
   <span class="s2">&quot;stock&quot;</span> <span class="o">:</span> <span class="mi">10</span><span class="p">,</span>
   <span class="s2">&quot;info&quot;</span> <span class="o">:</span> <span class="p">{</span> <span class="s2">&quot;publisher&quot;</span> <span class="o">:</span> <span class="s2">&quot;2255&quot;</span><span class="p">,</span> <span class="s2">&quot;pages&quot;</span> <span class="o">:</span> <span class="mi">150</span> <span class="p">},</span>
   <span class="s2">&quot;tags&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;baking&quot;</span><span class="p">,</span> <span class="s2">&quot;cooking&quot;</span> <span class="p">]</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<p>This operation corresponds to the following SQL statements:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-sql"><div class="highlight"><pre><span></span><span class="k">DELETE</span> <span class="k">from</span> <span class="n">books</span> <span class="k">WHERE</span> <span class="n">_id</span> <span class="o">=</span> <span class="mi">2</span>

<span class="k">INSERT</span> <span class="k">INTO</span> <span class="n">books</span>
            <span class="p">(</span><span class="n">_id</span><span class="p">,</span>
             <span class="n">item</span><span class="p">,</span>
             <span class="n">stock</span><span class="p">,</span>
             <span class="n">publisher</span><span class="p">,</span>
             <span class="n">pages</span><span class="p">,</span>
             <span class="n">tags</span><span class="p">)</span>
<span class="k">VALUES</span>     <span class="p">(</span><span class="mi">2</span><span class="p">,</span>
            <span class="ss">&quot;xyz123&quot;</span><span class="p">,</span>
            <span class="mi">10</span><span class="p">,</span>
            <span class="ss">&quot;2255&quot;</span><span class="p">,</span>
            <span class="mi">150</span><span class="p">,</span>
            <span class="ss">&quot;baking,cooking&quot;</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
<div class="tabpanel-updatemultiple" data-tabid="updatemultiple"><p>From the <a class="reference internal" href="../program/mongo.html#bin.mongo" title="bin.mongo"><code class="xref mongodb mongodb-binary docutils literal"><span class="pre">mongo</span></code></a> shell, create a <code class="docutils literal"><span class="pre">books</span></code> collection which
contains the following documents. This command first removes all
previously existing documents from the <code class="docutils literal"><span class="pre">books</span></code> collection:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">books</span><span class="p">.</span><span class="nx">remove</span><span class="p">({});</span>

<span class="nx">db</span><span class="p">.</span><span class="nx">books</span><span class="p">.</span><span class="nx">insertMany</span><span class="p">([</span>
  <span class="p">{</span>
    <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span>
    <span class="s2">&quot;item&quot;</span> <span class="o">:</span> <span class="s2">&quot;TBD&quot;</span><span class="p">,</span>
    <span class="s2">&quot;stock&quot;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">,</span>
    <span class="s2">&quot;info&quot;</span> <span class="o">:</span> <span class="p">{</span> <span class="s2">&quot;publisher&quot;</span> <span class="o">:</span> <span class="s2">&quot;1111&quot;</span><span class="p">,</span> <span class="s2">&quot;pages&quot;</span> <span class="o">:</span> <span class="mi">430</span> <span class="p">},</span>
    <span class="s2">&quot;tags&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;technology&quot;</span><span class="p">,</span> <span class="s2">&quot;computer&quot;</span> <span class="p">],</span>
    <span class="s2">&quot;ratings&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;ijk&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">4</span> <span class="p">},</span> <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;lmn&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">5</span> <span class="p">}</span> <span class="p">],</span>
    <span class="s2">&quot;reorder&quot;</span> <span class="o">:</span> <span class="kc">false</span>
   <span class="p">},</span>
   <span class="p">{</span>
    <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">2</span><span class="p">,</span>
    <span class="s2">&quot;item&quot;</span> <span class="o">:</span> <span class="s2">&quot;XYZ123&quot;</span><span class="p">,</span>
    <span class="s2">&quot;stock&quot;</span> <span class="o">:</span> <span class="mi">15</span><span class="p">,</span>
    <span class="s2">&quot;info&quot;</span> <span class="o">:</span> <span class="p">{</span> <span class="s2">&quot;publisher&quot;</span> <span class="o">:</span> <span class="s2">&quot;5555&quot;</span><span class="p">,</span> <span class="s2">&quot;pages&quot;</span> <span class="o">:</span> <span class="mi">150</span> <span class="p">},</span>
    <span class="s2">&quot;tags&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="p">],</span>
    <span class="s2">&quot;ratings&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;xyz&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">5</span> <span class="p">}</span> <span class="p">],</span>
    <span class="s2">&quot;reorder&quot;</span> <span class="o">:</span> <span class="kc">false</span>
   <span class="p">}</span>
<span class="p">]);</span>
</pre></div>
</div>
</div>
<p>If <code class="docutils literal"><span class="pre">multi</span></code> is set to <code class="docutils literal"><span class="pre">true</span></code>, the
<a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> method updates <em>all</em> documents
that meet the <code class="docutils literal"><span class="pre">&lt;query&gt;</span></code> criteria. The <code class="docutils literal"><span class="pre">multi</span></code> update
operation may interleave with other read/write operations.</p>
<p>The following operation sets the <code class="docutils literal"><span class="pre">reorder</span></code> field to <code class="docutils literal"><span class="pre">true</span></code>
for all documents where <code class="docutils literal"><span class="pre">stock</span></code> is less than or equal to
<code class="docutils literal"><span class="pre">10</span></code>. If the <code class="docutils literal"><span class="pre">reorder</span></code> field does not exist in the matching
document(s), the <a class="reference internal" href="../operator/update/set.html#up._S_set" title="$set"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$set</span></code></a> operator adds the field
with the specified value.</p>
<p>You can use the web shell below to insert the sample
documents and execute the example update operation:</p>
<iframe class="mws-root" allowfullscreen sandbox="allow-scripts allow-same-origin" width=100% height=320 src="https://mws.mongodb.com/?version=4.2"></iframe><div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">books</span><span class="p">.</span><span class="nx">update</span><span class="p">(</span>
   <span class="p">{</span> <span class="nx">stock</span><span class="o">:</span> <span class="p">{</span> <span class="nx">$lte</span><span class="o">:</span> <span class="mi">10</span> <span class="p">}</span> <span class="p">},</span>
   <span class="p">{</span> <span class="nx">$set</span><span class="o">:</span> <span class="p">{</span> <span class="nx">reorder</span><span class="o">:</span> <span class="kc">true</span> <span class="p">}</span> <span class="p">},</span>
   <span class="p">{</span> <span class="nx">multi</span><span class="o">:</span> <span class="kc">true</span> <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<p>The resulting documents in the collection are the following:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="p">[</span>
  <span class="p">{</span>
    <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span>
    <span class="s2">&quot;item&quot;</span> <span class="o">:</span> <span class="s2">&quot;ABC123&quot;</span><span class="p">,</span>
    <span class="s2">&quot;stock&quot;</span> <span class="o">:</span> <span class="mi">5</span><span class="p">,</span>
    <span class="s2">&quot;info&quot;</span> <span class="o">:</span> <span class="p">{</span>
     <span class="s2">&quot;publisher&quot;</span> <span class="o">:</span> <span class="s2">&quot;2222&quot;</span><span class="p">,</span>
     <span class="s2">&quot;pages&quot;</span> <span class="o">:</span> <span class="mi">430</span>
    <span class="p">},</span>
    <span class="s2">&quot;ratings&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;ijk&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">4</span> <span class="p">},</span> <span class="p">{</span> <span class="s2">&quot;by&quot;</span> <span class="o">:</span> <span class="s2">&quot;xyz&quot;</span><span class="p">,</span> <span class="s2">&quot;rating&quot;</span> <span class="o">:</span> <span class="mi">3</span> <span class="p">}</span> <span class="p">],</span>
<span class="hll">    <span class="s2">&quot;reorder&quot;</span> <span class="o">:</span> <span class="kc">true</span>
</span>   <span class="p">}</span>
   <span class="p">{</span>
     <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">2</span><span class="p">,</span>
     <span class="s2">&quot;item&quot;</span> <span class="o">:</span> <span class="s2">&quot;XYZ123&quot;</span><span class="p">,</span>
     <span class="s2">&quot;stock&quot;</span> <span class="o">:</span> <span class="mi">10</span><span class="p">,</span>
     <span class="s2">&quot;info&quot;</span> <span class="o">:</span> <span class="p">{</span> <span class="s2">&quot;publisher&quot;</span> <span class="o">:</span> <span class="s2">&quot;2255&quot;</span><span class="p">,</span> <span class="s2">&quot;pages&quot;</span> <span class="o">:</span> <span class="mi">150</span> <span class="p">},</span>
     <span class="s2">&quot;tags&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;baking&quot;</span><span class="p">,</span> <span class="s2">&quot;cooking&quot;</span> <span class="p">],</span>
<span class="hll">     <span class="s2">&quot;reorder&quot;</span> <span class="o">:</span> <span class="kc">true</span>
</span>   <span class="p">}</span>
<span class="p">]</span>
</pre></div>
</div>
</div>
<p>This operation corresponds to the following SQL statement:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-sql"><div class="highlight"><pre><span></span><span class="k">UPDATE</span> <span class="n">books</span>
<span class="k">SET</span> <span class="n">reorder</span><span class="o">=</span><span class="k">true</span>
<span class="k">WHERE</span> <span class="n">stock</span> <span class="o">&lt;=</span> <span class="mi">10</span>
</pre></div>
</div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">You cannot specify <code class="docutils literal"><span class="pre">multi:</span> <span class="pre">true</span></code> when performing a
replacement, i.e., when the <a class="reference internal" href="#update-parameter"><span class="std std-ref">&lt;update&gt;</span></a> document contains <em>only</em>
<code class="docutils literal"><span class="pre">field:value</span></code> expressions.</p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="../operator/update/set.html#up._S_set" title="$set"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$set</span></code></a></p>
</div>
    </div>
  </div>
</div></div>
<div class="section" id="insert-a-new-document-if-no-match-exists-upsert">
<span id="upsert-behavior"></span><span id="upsert-parameter"></span><span id="example-update-upsert"></span><h3>Insert a New Document if No Match Exists (<code class="docutils literal"><span class="pre">Upsert</span></code>)<a class="headerlink" href="#insert-a-new-document-if-no-match-exists-upsert" title="Permalink to this headline">¶</a></h3>
<p>When you specify the option <a class="reference internal" href="#update-upsert"><span class="std std-ref">upsert: true</span></a>:</p>
<ul class="simple">
<li>If document(s) match the query criteria,
<a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> performs an update.</li>
<li>If no document matches the query criteria,
<a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> inserts a <em>single</em> document.</li>
</ul>
<p>If you specify <code class="docutils literal"><span class="pre">upsert:</span> <span class="pre">true</span></code> on a sharded collection, you must
include the full shard key in the <code class="docutils literal"><span class="pre">filter</span></code>. For additional
<a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> behavior on a sharded collection, see
<a class="reference internal" href="#update-sharded-collection"><span class="std std-ref">Sharded Collections</span></a>.</p>
<div class="docutils container">
<div class="tabs" >
  <ul class="tab-strip tab-strip--singleton" role="tablist">
    <li class="tab-strip__element" data-tabid="upsertexample" role="tab" aria-selected="true">Upsert with Replacement Document</li>
    <li class="tab-strip__element" data-tabid="upsertopexpr" role="tab" aria-selected="false">Upsert with Operator Expressions</li>
    <li class="tab-strip__element" data-tabid="aggpipelineupsert" role="tab" aria-selected="false">Aggregation Pipeline using Upsert</li>
    <li class="tab-strip__element" data-tabid="combineupsertmulti" role="tab" aria-selected="false">Combine Upsert and Multi Options</li>
    <li class="tab-strip__element" data-tabid="upsertdottedid" role="tab" aria-selected="false">Upsert with Dotted _id Query</li>
  </ul>
  <div class="tabs__content" role="tabpanel">
    <div class="tabpanel-upsertexample" data-tabid="upsertexample"><p>If no document matches the query criteria and the <code class="docutils literal"><span class="pre">&lt;update&gt;</span></code>
parameter is a replacement document (i.e., contains only field
and value pairs), the update inserts a new document with the
fields and values of the replacement document.</p>
<ul>
<li><p class="first">If you specify an <code class="docutils literal"><span class="pre">_id</span></code> field in either the query parameter
or replacement document, MongoDB uses that <code class="docutils literal"><span class="pre">_id</span></code> field in the
inserted document.</p>
</li>
<li><p class="first">If you do not specify an <code class="docutils literal"><span class="pre">_id</span></code> field in either the query
parameter or replacement document, MongoDB generates adds the
<code class="docutils literal"><span class="pre">_id</span></code> field with a randomly generated <a class="reference internal" href="../bson-types.html#objectid"><span class="std std-ref">ObjectId</span></a>
value.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">You cannot specify different <code class="docutils literal"><span class="pre">_id</span></code> field values in the
query parameter and replacement document. If you do, the
operation errors.</p>
</div>
</li>
</ul>
<p>For example, the following update sets the <a class="reference internal" href="#upsert-parameter"><span class="std std-ref">upsert</span></a> option to <code class="docutils literal"><span class="pre">true</span></code>:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">books</span><span class="p">.</span><span class="nx">update</span><span class="p">(</span>
   <span class="p">{</span> <span class="nx">item</span><span class="o">:</span> <span class="s2">&quot;ZZZ135&quot;</span> <span class="p">},</span>   <span class="c1">// Query parameter</span>
   <span class="p">{</span>                     <span class="c1">// Replacement document</span>
     <span class="nx">item</span><span class="o">:</span> <span class="s2">&quot;ZZZ135&quot;</span><span class="p">,</span>
     <span class="nx">stock</span><span class="o">:</span> <span class="mi">5</span><span class="p">,</span>
     <span class="nx">tags</span><span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;database&quot;</span> <span class="p">]</span>
   <span class="p">},</span>
<span class="hll">   <span class="p">{</span> <span class="nx">upsert</span><span class="o">:</span> <span class="kc">true</span> <span class="p">}</span>      <span class="c1">// Options</span>
</span><span class="p">)</span>
</pre></div>
</div>
</div>
<p>If no document matches the <code class="docutils literal"><span class="pre">&lt;query&gt;</span></code> parameter, the update
operation inserts a document with <em>only</em> the replacement
document. Because no <code class="docutils literal"><span class="pre">_id</span></code> field was specified in the
replacement document or query document, the operation creates a
new unique <code class="docutils literal"><span class="pre">ObjectId</span></code> for the new document’s <code class="docutils literal"><span class="pre">_id</span></code> field.
You can see the <code class="docutils literal"><span class="pre">upsert</span></code> reflected in the <a class="reference internal" href="#writeresults-update"><span class="std std-ref">WriteResult</span></a> of the operation:</p>
<div class="button-code-block">
<div class="button-row">
</div>
<div class="highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">WriteResult</span><span class="p">({</span>
  <span class="s2">&quot;nMatched&quot;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">,</span>
  <span class="s2">&quot;nUpserted&quot;</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span>
  <span class="s2">&quot;nModified&quot;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">,</span>
  <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="nx">ObjectId</span><span class="p">(</span><span class="s2">&quot;5da78973835b2f1c75347a83&quot;</span><span class="p">)</span>
 <span class="p">})</span>
</pre></div>
</div>
</div>
<p>The operation inserts the following document into the <code class="docutils literal"><span class="pre">books</span></code>
collection (your <a class="reference internal" href="../bson-types.html#objectid"><span class="std std-ref">ObjectId</span></a> value will differ):</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="p">{</span>
  <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="nx">ObjectId</span><span class="p">(</span><span class="s2">&quot;5da78973835b2f1c75347a83&quot;</span><span class="p">),</span>
  <span class="s2">&quot;item&quot;</span> <span class="o">:</span> <span class="s2">&quot;ZZZ135&quot;</span><span class="p">,</span>
  <span class="s2">&quot;stock&quot;</span> <span class="o">:</span> <span class="mi">5</span><span class="p">,</span>
  <span class="s2">&quot;tags&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;database&quot;</span> <span class="p">]</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
</div>
<div class="tabpanel-upsertopexpr" data-tabid="upsertopexpr"><p>If no document matches the query criteria and the <code class="docutils literal"><span class="pre">&lt;update&gt;</span></code>
parameter is a document with <a class="reference internal" href="../operator/update.html#id1"><span class="std std-ref">update operator expressions</span></a>, then the operation creates a base document
from the equality clauses in the <code class="docutils literal"><span class="pre">&lt;query&gt;</span></code> parameter and
applies the expressions from the <code class="docutils literal"><span class="pre">&lt;update&gt;</span></code> parameter.</p>
<p><a class="reference internal" href="../operator/query.html"><span class="doc">Comparison</span></a> operations from
the <code class="docutils literal"><span class="pre">&lt;query&gt;</span></code> will not be included in the new document. If
the new document does not include the <code class="docutils literal"><span class="pre">_id</span></code> field, MongoDB
adds the <code class="docutils literal"><span class="pre">_id</span></code> field with an <a class="reference internal" href="../bson-types.html#objectid"><span class="std std-ref">ObjectId</span></a> value.</p>
<p>For example, the following update sets the <a class="reference internal" href="#upsert-parameter"><span class="std std-ref">upsert</span></a> option to <code class="docutils literal"><span class="pre">true</span></code>:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">books</span><span class="p">.</span><span class="nx">update</span><span class="p">(</span>
   <span class="p">{</span> <span class="nx">item</span><span class="o">:</span> <span class="s2">&quot;BLP921&quot;</span> <span class="p">},</span>   <span class="c1">// Query parameter</span>
   <span class="p">{</span>                     <span class="c1">// Update document</span>
      <span class="nx">$set</span><span class="o">:</span> <span class="p">{</span> <span class="nx">reorder</span><span class="o">:</span> <span class="kc">false</span> <span class="p">},</span>
      <span class="nx">$setOnInsert</span><span class="o">:</span> <span class="p">{</span> <span class="nx">stock</span><span class="o">:</span> <span class="mi">10</span> <span class="p">}</span>
   <span class="p">},</span>
   <span class="p">{</span> <span class="nx">upsert</span><span class="o">:</span> <span class="kc">true</span> <span class="p">}</span>      <span class="c1">// Options</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<p>If no documents match the query condition, the operation
inserts the following document (your <a class="reference internal" href="../bson-types.html#objectid"><span class="std std-ref">ObjectId</span></a> value
will differ):</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="p">{</span>
  <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="nx">ObjectId</span><span class="p">(</span><span class="s2">&quot;5da79019835b2f1c75348a0a&quot;</span><span class="p">),</span>
  <span class="s2">&quot;item&quot;</span> <span class="o">:</span> <span class="s2">&quot;BLP921&quot;</span><span class="p">,</span>
  <span class="s2">&quot;reorder&quot;</span> <span class="o">:</span> <span class="kc">false</span><span class="p">,</span>
  <span class="s2">&quot;stock&quot;</span> <span class="o">:</span> <span class="mi">10</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="../operator/update/setOnInsert.html#up._S_setOnInsert" title="$setOnInsert"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$setOnInsert</span></code></a></p>
</div>
</div>
<div class="tabpanel-aggpipelineupsert" data-tabid="aggpipelineupsert"><p>If the <code class="docutils literal"><span class="pre">&lt;update&gt;</span></code> parameter is an <a class="reference internal" href="#update-behavior-agg-pipeline"><span class="std std-ref">aggregation pipeline</span></a>, the update creates a base
document from the equality clauses in the <code class="docutils literal"><span class="pre">&lt;query&gt;</span></code>
parameter, and then applies the pipeline to the document to
create the document to insert. If the new document does not
include the <code class="docutils literal"><span class="pre">_id</span></code> field, MongoDB adds the <code class="docutils literal"><span class="pre">_id</span></code> field with
an <a class="reference internal" href="../bson-types.html#objectid"><span class="std std-ref">ObjectId</span></a> value.</p>
<p>For example, the following <a class="reference internal" href="#upsert-parameter"><span class="std std-ref">upsert: true</span></a> operation specifies an aggregation pipeline that uses</p>
<ul class="simple">
<li>the <a class="reference internal" href="../operator/aggregation/replaceRoot.html#pipe._S_replaceRoot" title="$replaceRoot"><code class="xref mongodb mongodb-pipeline docutils literal"><span class="pre">$replaceRoot</span></code></a> stage which can provide
somewhat similar behavior to a <a class="reference internal" href="../operator/update/setOnInsert.html#up._S_setOnInsert" title="$setOnInsert"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$setOnInsert</span></code></a>
update operator expression,</li>
<li>the <a class="reference internal" href="../operator/aggregation/set.html#pipe._S_set" title="$set"><code class="xref mongodb mongodb-pipeline docutils literal"><span class="pre">$set</span></code></a> stage which can provide similar
behavior to the <a class="reference internal" href="../operator/update/set.html#up._S_set" title="$set"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$set</span></code></a> update operator expression,</li>
<li>the aggregation variable <a class="reference internal" href="../aggregation-variables.html#variable.NOW" title="NOW"><code class="xref mongodb mongodb-variable docutils literal"><span class="pre">NOW</span></code></a>, which resolves to
the current datetime and can provide similar behavior to the
<a class="reference internal" href="../operator/update/currentDate.html#up._S_currentDate" title="$currentDate"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$currentDate</span></code></a> update operator expression.</li>
</ul>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">books</span><span class="p">.</span><span class="nx">update</span><span class="p">(</span>
   <span class="p">{</span> <span class="nx">item</span><span class="o">:</span> <span class="s2">&quot;MRQ014&quot;</span><span class="p">,</span> <span class="nx">ratings</span><span class="o">:</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">3</span><span class="p">]</span> <span class="p">},</span> <span class="c1">// Query parameter</span>
   <span class="p">[</span>                                       <span class="c1">// Aggregation pipeline</span>
      <span class="p">{</span> <span class="nx">$replaceRoot</span><span class="o">:</span> <span class="p">{</span> <span class="nx">newRoot</span><span class="o">:</span> <span class="p">{</span> <span class="nx">$mergeObjects</span><span class="o">:</span> <span class="p">[</span> <span class="p">{</span> <span class="nx">stock</span><span class="o">:</span> <span class="mi">0</span> <span class="p">},</span> <span class="s2">&quot;$$ROOT&quot;</span>  <span class="p">]</span> <span class="p">}</span> <span class="p">}</span> <span class="p">},</span>
      <span class="p">{</span> <span class="nx">$set</span><span class="o">:</span> <span class="p">{</span> <span class="nx">avgRating</span><span class="o">:</span> <span class="p">{</span> <span class="nx">$avg</span><span class="o">:</span> <span class="s2">&quot;$ratings&quot;</span> <span class="p">},</span> <span class="nx">tags</span><span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;fiction&quot;</span><span class="p">,</span> <span class="s2">&quot;murder&quot;</span> <span class="p">],</span> <span class="nx">lastModified</span><span class="o">:</span> <span class="s2">&quot;$$NOW&quot;</span> <span class="p">}</span> <span class="p">}</span>
   <span class="p">],</span>
   <span class="p">{</span> <span class="nx">upsert</span><span class="o">:</span> <span class="kc">true</span> <span class="p">}</span>   <span class="c1">// Options</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<p>If no document matches the <code class="docutils literal"><span class="pre">&lt;query&gt;</span></code> parameter, the
operation inserts the following document into the <code class="docutils literal"><span class="pre">books</span></code>
collection (your <a class="reference internal" href="../bson-types.html#objectid"><span class="std std-ref">ObjectId</span></a> value will differ):</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="p">{</span>
   <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="nx">ObjectId</span><span class="p">(</span><span class="s2">&quot;5e2921e0b4c550aad59d1ba9&quot;</span><span class="p">),</span>
   <span class="s2">&quot;stock&quot;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">,</span>
   <span class="s2">&quot;item&quot;</span> <span class="o">:</span> <span class="s2">&quot;MRQ014&quot;</span><span class="p">,</span>
   <span class="s2">&quot;ratings&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">3</span> <span class="p">],</span>
   <span class="s2">&quot;avgRating&quot;</span> <span class="o">:</span> <span class="mf">3.3333333333333335</span><span class="p">,</span>
   <span class="s2">&quot;tags&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;fiction&quot;</span><span class="p">,</span> <span class="s2">&quot;murder&quot;</span> <span class="p">],</span>
   <span class="s2">&quot;lastModified&quot;</span> <span class="o">:</span> <span class="nx">ISODate</span><span class="p">(</span><span class="s2">&quot;2020-01-23T04:32:32.951Z&quot;</span><span class="p">)</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">For additional examples of updates using
aggregation pipelines, see <a class="reference internal" href="#update-behavior-agg-pipeline"><span class="std std-ref">Update with Aggregation Pipeline</span></a>.</p>
</div>
</div>
<div class="tabpanel-combineupsertmulti" data-tabid="combineupsertmulti"><h4>Combine Upsert and Multi Options (Match)</h4><p>From the <a class="reference internal" href="../program/mongo.html#bin.mongo" title="bin.mongo"><code class="xref mongodb mongodb-binary docutils literal"><span class="pre">mongo</span></code></a> shell, insert the following
documents into a <code class="docutils literal"><span class="pre">books</span></code> collection:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">books</span><span class="p">.</span><span class="nx">insertMany</span><span class="p">([</span>
  <span class="p">{</span>
    <span class="nx">_id</span><span class="o">:</span> <span class="mi">5</span><span class="p">,</span>
    <span class="nx">item</span><span class="o">:</span> <span class="s2">&quot;RQM909&quot;</span><span class="p">,</span>
    <span class="nx">stock</span><span class="o">:</span> <span class="mi">18</span><span class="p">,</span>
    <span class="nx">info</span><span class="o">:</span> <span class="p">{</span> <span class="nx">publisher</span><span class="o">:</span> <span class="s2">&quot;0000&quot;</span><span class="p">,</span> <span class="nx">pages</span><span class="o">:</span> <span class="mi">170</span> <span class="p">},</span>
    <span class="nx">reorder</span><span class="o">:</span> <span class="kc">true</span>
  <span class="p">},</span>
  <span class="p">{</span>
    <span class="nx">_id</span><span class="o">:</span> <span class="mi">6</span><span class="p">,</span>
    <span class="nx">item</span><span class="o">:</span> <span class="s2">&quot;EFG222&quot;</span><span class="p">,</span>
    <span class="nx">stock</span><span class="o">:</span> <span class="mi">15</span><span class="p">,</span>
    <span class="nx">info</span><span class="o">:</span> <span class="p">{</span> <span class="nx">publisher</span><span class="o">:</span> <span class="s2">&quot;1111&quot;</span><span class="p">,</span> <span class="nx">pages</span><span class="o">:</span> <span class="mi">72</span> <span class="p">},</span>
    <span class="nx">reorder</span><span class="o">:</span> <span class="kc">true</span>
  <span class="p">}</span>
<span class="p">])</span>
</pre></div>
</div>
</div>
<p>The following operation specifies both the <code class="docutils literal"><span class="pre">multi</span></code> option and
the <code class="docutils literal"><span class="pre">upsert</span></code> option. If matching documents exist, the
operation updates all matching documents. If no matching
documents exist, the operation inserts a new document.</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">books</span><span class="p">.</span><span class="nx">update</span><span class="p">(</span>
   <span class="p">{</span> <span class="nx">stock</span><span class="o">:</span> <span class="p">{</span> <span class="nx">$gte</span><span class="o">:</span> <span class="mi">10</span> <span class="p">}</span> <span class="p">},</span>        <span class="c1">// Query parameter</span>
   <span class="p">{</span>                               <span class="c1">// Update document</span>
     <span class="nx">$set</span><span class="o">:</span> <span class="p">{</span> <span class="nx">reorder</span><span class="o">:</span> <span class="kc">false</span><span class="p">,</span> <span class="nx">tags</span><span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;literature&quot;</span><span class="p">,</span> <span class="s2">&quot;translated&quot;</span> <span class="p">]</span> <span class="p">}</span>
   <span class="p">},</span>
   <span class="p">{</span> <span class="nx">upsert</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">multi</span><span class="o">:</span> <span class="kc">true</span> <span class="p">}</span>   <span class="c1">// Options</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<p>The operation updates all matching documents and results in the
following:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="p">{</span>
   <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">5</span><span class="p">,</span>
   <span class="s2">&quot;item&quot;</span> <span class="o">:</span> <span class="s2">&quot;RQM909&quot;</span><span class="p">,</span>
   <span class="s2">&quot;stock&quot;</span> <span class="o">:</span> <span class="mi">18</span><span class="p">,</span>
   <span class="s2">&quot;info&quot;</span> <span class="o">:</span> <span class="p">{</span> <span class="s2">&quot;publisher&quot;</span> <span class="o">:</span> <span class="s2">&quot;0000&quot;</span><span class="p">,</span> <span class="s2">&quot;pages&quot;</span> <span class="o">:</span> <span class="mi">170</span> <span class="p">},</span>
   <span class="s2">&quot;reorder&quot;</span> <span class="o">:</span> <span class="kc">false</span><span class="p">,</span>
   <span class="s2">&quot;tags&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;literature&quot;</span><span class="p">,</span> <span class="s2">&quot;translated&quot;</span> <span class="p">]</span>
<span class="p">}</span>
<span class="p">{</span>
   <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">6</span><span class="p">,</span>
   <span class="s2">&quot;item&quot;</span> <span class="o">:</span> <span class="s2">&quot;EFG222&quot;</span><span class="p">,</span>
   <span class="s2">&quot;stock&quot;</span> <span class="o">:</span> <span class="mi">15</span><span class="p">,</span>
   <span class="s2">&quot;info&quot;</span> <span class="o">:</span> <span class="p">{</span> <span class="s2">&quot;publisher&quot;</span> <span class="o">:</span> <span class="s2">&quot;1111&quot;</span><span class="p">,</span> <span class="s2">&quot;pages&quot;</span> <span class="o">:</span> <span class="mi">72</span> <span class="p">},</span>
   <span class="s2">&quot;reorder&quot;</span> <span class="o">:</span> <span class="kc">false</span><span class="p">,</span>
   <span class="s2">&quot;tags&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;literature&quot;</span><span class="p">,</span> <span class="s2">&quot;translated&quot;</span> <span class="p">]</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<h4>Combine Upsert and Multi Options (No Match)</h4><p>If the collection had <em>no</em> matching document, the operation
would result in the insertion of a single document using the
fields from both the <code class="docutils literal"><span class="pre">&lt;query&gt;</span></code> and the <code class="docutils literal"><span class="pre">&lt;update&gt;</span></code>
specifications. For example, consider the following operation:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">books</span><span class="p">.</span><span class="nx">update</span><span class="p">(</span>
  <span class="p">{</span> <span class="s2">&quot;info.publisher&quot;</span><span class="o">:</span> <span class="s2">&quot;Self-Published&quot;</span> <span class="p">},</span>   <span class="c1">// Query parameter</span>
  <span class="p">{</span>                                         <span class="c1">// Update document</span>
    <span class="nx">$set</span><span class="o">:</span> <span class="p">{</span> <span class="nx">reorder</span><span class="o">:</span> <span class="kc">false</span><span class="p">,</span> <span class="nx">tags</span><span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;literature&quot;</span><span class="p">,</span> <span class="s2">&quot;hardcover&quot;</span> <span class="p">],</span> <span class="nx">stock</span><span class="o">:</span> <span class="mi">25</span> <span class="p">}</span>
  <span class="p">},</span>
  <span class="p">{</span> <span class="nx">upsert</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">multi</span><span class="o">:</span> <span class="kc">true</span> <span class="p">}</span>             <span class="c1">// Options</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<p>The operation inserts the following document into the <code class="docutils literal"><span class="pre">books</span></code>
collection (your <a class="reference internal" href="../bson-types.html#objectid"><span class="std std-ref">ObjectId</span></a> value will differ):</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="p">{</span>
  <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="nx">ObjectId</span><span class="p">(</span><span class="s2">&quot;5db337934f670d584b6ca8e0&quot;</span><span class="p">),</span>
  <span class="s2">&quot;info&quot;</span> <span class="o">:</span> <span class="p">{</span> <span class="s2">&quot;publisher&quot;</span> <span class="o">:</span> <span class="s2">&quot;Self-Published&quot;</span> <span class="p">},</span>
  <span class="s2">&quot;reorder&quot;</span> <span class="o">:</span> <span class="kc">false</span><span class="p">,</span>
  <span class="s2">&quot;stock&quot;</span> <span class="o">:</span> <span class="mi">25</span><span class="p">,</span>
  <span class="s2">&quot;tags&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;literature&quot;</span><span class="p">,</span> <span class="s2">&quot;hardcover&quot;</span> <span class="p">]</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
</div>
<div class="tabpanel-upsertdottedid" data-tabid="upsertdottedid"><p>When you execute an <a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">update()</span></code></a> with <code class="docutils literal"><span class="pre">upsert:</span>
<span class="pre">true</span></code> and the query matches no existing document, MongoDB will refuse
to insert a new document if the query specifies conditions on the
<code class="docutils literal"><span class="pre">_id</span></code> field using <a class="reference internal" href="../../core/document.html#document-dot-notation"><span class="std std-ref">dot notation</span></a>.</p>
<p>This restriction ensures that the order of fields embedded in the
<code class="docutils literal"><span class="pre">_id</span></code> document is well-defined and not bound to the order specified in
the query.</p>
<p>If you attempt to insert a document in this way, MongoDB will raise an
error. For example, consider the following update operation. Since the
update operation specifies <code class="docutils literal"><span class="pre">upsert:true</span></code> and the query specifies
conditions on the <code class="docutils literal"><span class="pre">_id</span></code> field using dot notation, then the update will
result in an error when constructing the document to insert.</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">collection</span><span class="p">.</span><span class="nx">update</span><span class="p">(</span> <span class="p">{</span> <span class="s2">&quot;_id.name&quot;</span><span class="o">:</span> <span class="s2">&quot;Robert Frost&quot;</span><span class="p">,</span> <span class="s2">&quot;_id.uid&quot;</span><span class="o">:</span> <span class="mi">0</span> <span class="p">},</span>
   <span class="p">{</span> <span class="s2">&quot;categories&quot;</span><span class="o">:</span> <span class="p">[</span><span class="s2">&quot;poet&quot;</span><span class="p">,</span> <span class="s2">&quot;playwright&quot;</span><span class="p">]</span> <span class="p">},</span>
   <span class="p">{</span> <span class="nx">upsert</span><span class="o">:</span> <span class="kc">true</span> <span class="p">}</span> <span class="p">)</span>
</pre></div>
</div>
</div>
<p>The <code class="docutils literal"><span class="pre">WriteResult</span></code> of the operation returns the following
error:</p>
<div class="button-code-block">
<div class="button-row">
</div>
<div class="highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">WriteResult</span><span class="p">({</span>
  <span class="s2">&quot;nMatched&quot;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">,</span>
  <span class="s2">&quot;nUpserted&quot;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">,</span>
  <span class="s2">&quot;nModified&quot;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">,</span>
  <span class="s2">&quot;writeError&quot;</span> <span class="o">:</span> <span class="p">{</span>
    <span class="s2">&quot;code&quot;</span> <span class="o">:</span> <span class="mi">111</span><span class="p">,</span>
    <span class="s2">&quot;errmsg&quot;</span> <span class="o">:</span> <span class="s2">&quot;field at &#39;_id&#39; must be exactly specified, field at sub-path &#39;_id.name&#39;found&quot;</span>
  <span class="p">}</span>
<span class="p">})</span>
</pre></div>
</div>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="WriteResult.html#WriteResult" title="WriteResult()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">WriteResult()</span></code></a></p>
</div>
    </div>
  </div>
</div></div>
<div class="section" id="use-unique-indexes">
<span id="update-with-unique-indexes"></span><h4>Use Unique Indexes<a class="headerlink" href="#use-unique-indexes" title="Permalink to this headline">¶</a></h4>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">To avoid inserting the same document more than once,
only use <code class="docutils literal"><span class="pre">upsert:</span> <span class="pre">true</span></code> if the <code class="docutils literal"><span class="pre">query</span></code> field is uniquely
indexed.</p>
</div>
<p>Given a collection named <code class="docutils literal"><span class="pre">people</span></code> where no documents have
a <code class="docutils literal"><span class="pre">name</span></code> field that holds the value <code class="docutils literal"><span class="pre">Andy</span></code>, consider when multiple
clients issue the following <a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> with
<code class="docutils literal"><span class="pre">upsert:</span> <span class="pre">true</span></code> at the same time:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">people</span><span class="p">.</span><span class="nx">update</span><span class="p">(</span>
   <span class="p">{</span> <span class="nx">name</span><span class="o">:</span> <span class="s2">&quot;Andy&quot;</span> <span class="p">},</span>   <span class="c1">// Query parameter</span>
   <span class="p">{</span>                   <span class="c1">// Update document</span>
      <span class="nx">name</span><span class="o">:</span> <span class="s2">&quot;Andy&quot;</span><span class="p">,</span>
      <span class="nx">rating</span><span class="o">:</span> <span class="mi">1</span><span class="p">,</span>
      <span class="nx">score</span><span class="o">:</span> <span class="mi">1</span>
   <span class="p">},</span>
   <span class="p">{</span> <span class="nx">upsert</span><span class="o">:</span> <span class="kc">true</span> <span class="p">}</span>    <span class="c1">// Options</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<p>If all <a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> operations complete the
<code class="docutils literal"><span class="pre">query</span></code> portion before any client successfully inserts data, <strong>and</strong>
there is no unique index on the <code class="docutils literal"><span class="pre">name</span></code> field, then each update
operation may result in an insert.</p>
<p>To prevent MongoDB from inserting the same document more than once,
create a <a class="reference internal" href="../../core/index-unique.html#index-type-unique"><span class="std std-ref">unique index</span></a> on the <code class="docutils literal"><span class="pre">name</span></code> field.
With a unique index, if multiple applications issue the same update
with <code class="docutils literal"><span class="pre">upsert:</span> <span class="pre">true</span></code>, <em>exactly one</em>
<a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> would successfully insert a new
document.</p>
<p>The remaining operations would either:</p>
<ul>
<li><p class="first">update the newly inserted document, or</p>
</li>
<li><p class="first">fail when they attempted to insert a duplicate.</p>
<p>If the operation fails because of a duplicate index key error,
applications may retry the operation which will succeed as an update
operation.</p>
</li>
</ul>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="../operator/update/setOnInsert.html#up._S_setOnInsert" title="$setOnInsert"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$setOnInsert</span></code></a></p>
</div>
</div>
</div>
<div class="section" id="update-with-aggregation-pipeline">
<span id="update-example-agg"></span><span id="update-behavior-agg-pipeline"></span><h3>Update with Aggregation Pipeline<a class="headerlink" href="#update-with-aggregation-pipeline" title="Permalink to this headline">¶</a></h3>
<p>Starting in MongoDB 4.2, the <a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> method
can accept an <a class="reference internal" href="../../core/aggregation-pipeline.html"><span class="doc">aggregation pipeline</span></a> <code class="docutils literal"><span class="pre">[</span> <span class="pre">&lt;stage1&gt;,</span> <span class="pre">&lt;stage2&gt;,</span> <span class="pre">...</span> <span class="pre">]</span></code> that
specifies the modifications to perform. The pipeline can consist of
the following stages:</p>
<ul class="simple">
<li><a class="reference internal" href="../operator/aggregation/addFields.html#pipe._S_addFields" title="$addFields"><code class="xref mongodb mongodb-pipeline docutils literal"><span class="pre">$addFields</span></code></a> and its alias <a class="reference internal" href="../operator/aggregation/set.html#pipe._S_set" title="$set"><code class="xref mongodb mongodb-pipeline docutils literal"><span class="pre">$set</span></code></a></li>
<li><a class="reference internal" href="../operator/aggregation/project.html#pipe._S_project" title="$project"><code class="xref mongodb mongodb-pipeline docutils literal"><span class="pre">$project</span></code></a> and its alias <a class="reference internal" href="../operator/aggregation/unset.html#pipe._S_unset" title="$unset"><code class="xref mongodb mongodb-pipeline docutils literal"><span class="pre">$unset</span></code></a></li>
<li><a class="reference internal" href="../operator/aggregation/replaceRoot.html#pipe._S_replaceRoot" title="$replaceRoot"><code class="xref mongodb mongodb-pipeline docutils literal"><span class="pre">$replaceRoot</span></code></a> and its alias <a class="reference internal" href="../operator/aggregation/replaceWith.html#pipe._S_replaceWith" title="$replaceWith"><code class="xref mongodb mongodb-pipeline docutils literal"><span class="pre">$replaceWith</span></code></a>.</li>
</ul>
<p>Using the aggregation pipeline allows for a more expressive update
statement, such as expressing conditional updates based on current
field values or updating one field using the value of another field(s).</p>
<div class="section" id="modify-a-field-using-the-values-of-the-other-fields-in-the-document">
<h4>Modify a Field Using the Values of the Other Fields in the Document<a class="headerlink" href="#modify-a-field-using-the-values-of-the-other-fields-in-the-document" title="Permalink to this headline">¶</a></h4>
<div class="docutils container">
<p>Create a <code class="docutils literal"><span class="pre">members</span></code> collection with the following documents:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">members</span><span class="p">.</span><span class="nx">insertMany</span><span class="p">([</span>
   <span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;member&quot;</span> <span class="o">:</span> <span class="s2">&quot;abc123&quot;</span><span class="p">,</span> <span class="s2">&quot;status&quot;</span> <span class="o">:</span> <span class="s2">&quot;A&quot;</span><span class="p">,</span> <span class="s2">&quot;points&quot;</span> <span class="o">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s2">&quot;misc1&quot;</span> <span class="o">:</span> <span class="s2">&quot;note to self: confirm status&quot;</span><span class="p">,</span> <span class="s2">&quot;misc2&quot;</span> <span class="o">:</span> <span class="s2">&quot;Need to activate&quot;</span><span class="p">,</span> <span class="s2">&quot;lastUpdate&quot;</span> <span class="o">:</span> <span class="nx">ISODate</span><span class="p">(</span><span class="s2">&quot;2019-01-01T00:00:00Z&quot;</span><span class="p">)</span> <span class="p">},</span>
   <span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s2">&quot;member&quot;</span> <span class="o">:</span> <span class="s2">&quot;xyz123&quot;</span><span class="p">,</span> <span class="s2">&quot;status&quot;</span> <span class="o">:</span> <span class="s2">&quot;A&quot;</span><span class="p">,</span> <span class="s2">&quot;points&quot;</span> <span class="o">:</span> <span class="mi">60</span><span class="p">,</span> <span class="s2">&quot;misc1&quot;</span> <span class="o">:</span> <span class="s2">&quot;reminder: ping me at 100pts&quot;</span><span class="p">,</span> <span class="s2">&quot;misc2&quot;</span> <span class="o">:</span> <span class="s2">&quot;Some random comment&quot;</span><span class="p">,</span> <span class="s2">&quot;lastUpdate&quot;</span> <span class="o">:</span> <span class="nx">ISODate</span><span class="p">(</span><span class="s2">&quot;2019-01-01T00:00:00Z&quot;</span><span class="p">)</span> <span class="p">}</span>
<span class="p">])</span>
</pre></div>
</div>
</div>
<p>Assume that instead of separate <code class="docutils literal"><span class="pre">misc1</span></code> and <code class="docutils literal"><span class="pre">misc2</span></code> fields, you
want to gather these into a new <code class="docutils literal"><span class="pre">comments</span></code> field. The following
update operation uses an aggregation pipeline to:</p>
<ul class="simple">
<li>add the new <code class="docutils literal"><span class="pre">comments</span></code> field and set the <code class="docutils literal"><span class="pre">lastUpdate</span></code> field.</li>
<li>remove the <code class="docutils literal"><span class="pre">misc1</span></code> and <code class="docutils literal"><span class="pre">misc2</span></code> fields for all documents in the
collection.</li>
</ul>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">members</span><span class="p">.</span><span class="nx">update</span><span class="p">(</span>
   <span class="p">{</span> <span class="p">},</span>
   <span class="p">[</span>
      <span class="p">{</span> <span class="nx">$set</span><span class="o">:</span> <span class="p">{</span> <span class="nx">status</span><span class="o">:</span> <span class="s2">&quot;Modified&quot;</span><span class="p">,</span> <span class="nx">comments</span><span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;$misc1&quot;</span><span class="p">,</span> <span class="s2">&quot;$misc2&quot;</span> <span class="p">],</span> <span class="nx">lastUpdate</span><span class="o">:</span> <span class="s2">&quot;$$NOW&quot;</span> <span class="p">}</span> <span class="p">},</span>
      <span class="p">{</span> <span class="nx">$unset</span><span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;misc1&quot;</span><span class="p">,</span> <span class="s2">&quot;misc2&quot;</span> <span class="p">]</span> <span class="p">}</span>
   <span class="p">],</span>
   <span class="p">{</span> <span class="nx">multi</span><span class="o">:</span> <span class="kc">true</span> <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The <code class="docutils literal"><span class="pre">$set</span></code> and <code class="docutils literal"><span class="pre">$unset</span></code> used in the pipeline refers to the
aggregation stages <a class="reference internal" href="../operator/aggregation/set.html#pipe._S_set" title="$set"><code class="xref mongodb mongodb-pipeline docutils literal"><span class="pre">$set</span></code></a> and <a class="reference internal" href="../operator/aggregation/unset.html#pipe._S_unset" title="$unset"><code class="xref mongodb mongodb-pipeline docutils literal"><span class="pre">$unset</span></code></a>
respectively, and not the update operators <a class="reference internal" href="../operator/update/set.html#up._S_set" title="$set"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$set</span></code></a> and
<a class="reference internal" href="../operator/update/unset.html#up._S_unset" title="$unset"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$unset</span></code></a>.</p>
</div>
<dl class="docutils">
<dt>First Stage</dt>
<dd><p class="first">The <a class="reference internal" href="../operator/aggregation/set.html#pipe._S_set" title="$set"><code class="xref mongodb mongodb-pipeline docutils literal"><span class="pre">$set</span></code></a> stage:</p>
<ul class="last simple">
<li>creates a new array field <code class="docutils literal"><span class="pre">comments</span></code> whose elements are the current
content of the <code class="docutils literal"><span class="pre">misc1</span></code> and <code class="docutils literal"><span class="pre">misc2</span></code> fields and</li>
<li>sets the field <code class="docutils literal"><span class="pre">lastUpdate</span></code> to the value of the aggregation
variable <a class="reference internal" href="../aggregation-variables.html#variable.NOW" title="NOW"><code class="xref mongodb mongodb-variable docutils literal"><span class="pre">NOW</span></code></a>. The aggregation variable
<a class="reference internal" href="../aggregation-variables.html#variable.NOW" title="NOW"><code class="xref mongodb mongodb-variable docutils literal"><span class="pre">NOW</span></code></a> resolves to the current datetime value and remains
the same throughout the pipeline. To access aggregation
variables, prefix the variable with double dollar signs <code class="docutils literal"><span class="pre">$$</span></code>
and enclose in quotes.</li>
</ul>
</dd>
<dt>Second Stage</dt>
<dd>The <a class="reference internal" href="../operator/aggregation/unset.html#pipe._S_unset" title="$unset"><code class="xref mongodb mongodb-pipeline docutils literal"><span class="pre">$unset</span></code></a> stage removes the <code class="docutils literal"><span class="pre">misc1</span></code> and <code class="docutils literal"><span class="pre">misc2</span></code> fields.</dd>
</dl>
<p>After the command, the collection contains the following documents:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;member&quot;</span> <span class="o">:</span> <span class="s2">&quot;abc123&quot;</span><span class="p">,</span> <span class="s2">&quot;status&quot;</span> <span class="o">:</span> <span class="s2">&quot;Modified&quot;</span><span class="p">,</span> <span class="s2">&quot;points&quot;</span> <span class="o">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s2">&quot;lastUpdate&quot;</span> <span class="o">:</span> <span class="nx">ISODate</span><span class="p">(</span><span class="s2">&quot;2020-01-23T05:11:45.784Z&quot;</span><span class="p">),</span> <span class="s2">&quot;comments&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;note to self: confirm status&quot;</span><span class="p">,</span> <span class="s2">&quot;Need to activate&quot;</span> <span class="p">]</span> <span class="p">}</span>
<span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s2">&quot;member&quot;</span> <span class="o">:</span> <span class="s2">&quot;xyz123&quot;</span><span class="p">,</span> <span class="s2">&quot;status&quot;</span> <span class="o">:</span> <span class="s2">&quot;Modified&quot;</span><span class="p">,</span> <span class="s2">&quot;points&quot;</span> <span class="o">:</span> <span class="mi">60</span><span class="p">,</span> <span class="s2">&quot;lastUpdate&quot;</span> <span class="o">:</span> <span class="nx">ISODate</span><span class="p">(</span><span class="s2">&quot;2020-01-23T05:11:45.784Z&quot;</span><span class="p">),</span> <span class="s2">&quot;comments&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;reminder: ping me at 100pts&quot;</span><span class="p">,</span> <span class="s2">&quot;Some random comment&quot;</span> <span class="p">]</span> <span class="p">}</span>
</pre></div>
</div>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="../../tutorial/update-documents-with-aggregation-pipeline.html"><span class="doc">Updates with Aggregation Pipeline</span></a></p>
</div>
</div>
</div>
<div class="section" id="perform-conditional-updates-based-on-current-field-values">
<h4>Perform Conditional Updates Based on Current Field Values<a class="headerlink" href="#perform-conditional-updates-based-on-current-field-values" title="Permalink to this headline">¶</a></h4>
<div class="docutils container">
<p>Create a <code class="docutils literal"><span class="pre">students3</span></code> collection with the following documents:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">students3</span><span class="p">.</span><span class="nx">insert</span><span class="p">([</span>
   <span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;tests&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="mi">95</span><span class="p">,</span> <span class="mi">92</span><span class="p">,</span> <span class="mi">90</span> <span class="p">],</span> <span class="s2">&quot;lastUpdate&quot;</span> <span class="o">:</span> <span class="nx">ISODate</span><span class="p">(</span><span class="s2">&quot;2019-01-01T00:00:00Z&quot;</span><span class="p">)</span> <span class="p">},</span>
   <span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s2">&quot;tests&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="mi">94</span><span class="p">,</span> <span class="mi">88</span><span class="p">,</span> <span class="mi">90</span> <span class="p">],</span> <span class="s2">&quot;lastUpdate&quot;</span> <span class="o">:</span> <span class="nx">ISODate</span><span class="p">(</span><span class="s2">&quot;2019-01-01T00:00:00Z&quot;</span><span class="p">)</span> <span class="p">},</span>
   <span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">3</span><span class="p">,</span> <span class="s2">&quot;tests&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="mi">70</span><span class="p">,</span> <span class="mi">75</span><span class="p">,</span> <span class="mi">82</span> <span class="p">],</span> <span class="s2">&quot;lastUpdate&quot;</span> <span class="o">:</span> <span class="nx">ISODate</span><span class="p">(</span><span class="s2">&quot;2019-01-01T00:00:00Z&quot;</span><span class="p">)</span> <span class="p">}</span>
<span class="p">]);</span>
</pre></div>
</div>
</div>
<p>Using an aggregation pipeline, you can update the documents with the
calculated grade average and letter grade.</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">students3</span><span class="p">.</span><span class="nx">update</span><span class="p">(</span>
   <span class="p">{</span> <span class="p">},</span>
   <span class="p">[</span>
     <span class="p">{</span> <span class="nx">$set</span><span class="o">:</span> <span class="p">{</span> <span class="nx">average</span> <span class="o">:</span> <span class="p">{</span> <span class="nx">$trunc</span><span class="o">:</span> <span class="p">[</span> <span class="p">{</span> <span class="nx">$avg</span><span class="o">:</span> <span class="s2">&quot;$tests&quot;</span> <span class="p">},</span> <span class="mi">0</span> <span class="p">]</span> <span class="p">},</span> <span class="nx">lastUpdate</span><span class="o">:</span> <span class="s2">&quot;$$NOW&quot;</span> <span class="p">}</span> <span class="p">},</span>
     <span class="p">{</span> <span class="nx">$set</span><span class="o">:</span> <span class="p">{</span> <span class="nx">grade</span><span class="o">:</span> <span class="p">{</span> <span class="nx">$switch</span><span class="o">:</span> <span class="p">{</span>
                           <span class="nx">branches</span><span class="o">:</span> <span class="p">[</span>
                               <span class="p">{</span> <span class="k">case</span><span class="o">:</span> <span class="p">{</span> <span class="nx">$gte</span><span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;$average&quot;</span><span class="p">,</span> <span class="mi">90</span> <span class="p">]</span> <span class="p">},</span> <span class="nx">then</span><span class="o">:</span> <span class="s2">&quot;A&quot;</span> <span class="p">},</span>
                               <span class="p">{</span> <span class="k">case</span><span class="o">:</span> <span class="p">{</span> <span class="nx">$gte</span><span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;$average&quot;</span><span class="p">,</span> <span class="mi">80</span> <span class="p">]</span> <span class="p">},</span> <span class="nx">then</span><span class="o">:</span> <span class="s2">&quot;B&quot;</span> <span class="p">},</span>
                               <span class="p">{</span> <span class="k">case</span><span class="o">:</span> <span class="p">{</span> <span class="nx">$gte</span><span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;$average&quot;</span><span class="p">,</span> <span class="mi">70</span> <span class="p">]</span> <span class="p">},</span> <span class="nx">then</span><span class="o">:</span> <span class="s2">&quot;C&quot;</span> <span class="p">},</span>
                               <span class="p">{</span> <span class="k">case</span><span class="o">:</span> <span class="p">{</span> <span class="nx">$gte</span><span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;$average&quot;</span><span class="p">,</span> <span class="mi">60</span> <span class="p">]</span> <span class="p">},</span> <span class="nx">then</span><span class="o">:</span> <span class="s2">&quot;D&quot;</span> <span class="p">}</span>
                           <span class="p">],</span>
                           <span class="k">default</span><span class="o">:</span> <span class="s2">&quot;F&quot;</span>
     <span class="p">}</span> <span class="p">}</span> <span class="p">}</span> <span class="p">}</span>
   <span class="p">],</span>
   <span class="p">{</span> <span class="nx">multi</span><span class="o">:</span> <span class="kc">true</span> <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The <code class="docutils literal"><span class="pre">$set</span></code> used in the pipeline refers to the aggregation stage
<a class="reference internal" href="../operator/aggregation/set.html#pipe._S_set" title="$set"><code class="xref mongodb mongodb-pipeline docutils literal"><span class="pre">$set</span></code></a>, and not the update operators <a class="reference internal" href="../operator/update/set.html#up._S_set" title="$set"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$set</span></code></a>.</p>
</div>
<dl class="docutils">
<dt>First Stage</dt>
<dd><p class="first">The <a class="reference internal" href="../operator/aggregation/set.html#pipe._S_set" title="$set"><code class="xref mongodb mongodb-pipeline docutils literal"><span class="pre">$set</span></code></a> stage:</p>
<ul class="last simple">
<li>calculates a new field <code class="docutils literal"><span class="pre">average</span></code> based on the average of the
<code class="docutils literal"><span class="pre">tests</span></code> field. See <a class="reference internal" href="../operator/aggregation/avg.html#grp._S_avg" title="$avg"><code class="xref mongodb mongodb-group docutils literal"><span class="pre">$avg</span></code></a> for more information on the
<code class="docutils literal"><span class="pre">$avg</span></code> aggregation operator and <a class="reference internal" href="../operator/aggregation/trunc.html#exp._S_trunc" title="$trunc"><code class="xref mongodb mongodb-expression docutils literal"><span class="pre">$trunc</span></code></a> for more
information on the  <code class="docutils literal"><span class="pre">$trunc</span></code> truncate aggregation operator.</li>
<li>sets the field <code class="docutils literal"><span class="pre">lastUpdate</span></code> to the value of the aggregation
variable <a class="reference internal" href="../aggregation-variables.html#variable.NOW" title="NOW"><code class="xref mongodb mongodb-variable docutils literal"><span class="pre">NOW</span></code></a>. The aggregation variable
<a class="reference internal" href="../aggregation-variables.html#variable.NOW" title="NOW"><code class="xref mongodb mongodb-variable docutils literal"><span class="pre">NOW</span></code></a> resolves to the current datetime value and remains
the same throughout the pipeline. To access aggregation
variables, prefix the variable with double dollar signs <code class="docutils literal"><span class="pre">$$</span></code>
and enclose in quotes.</li>
</ul>
</dd>
<dt>Second Stage</dt>
<dd>The <a class="reference internal" href="../operator/aggregation/set.html#pipe._S_set" title="$set"><code class="xref mongodb mongodb-pipeline docutils literal"><span class="pre">$set</span></code></a> stage calculates a new field <code class="docutils literal"><span class="pre">grade</span></code> based on
the <code class="docutils literal"><span class="pre">average</span></code> field calculated in the previous stage. See
<a class="reference internal" href="../operator/aggregation/switch.html#exp._S_switch" title="$switch"><code class="xref mongodb mongodb-expression docutils literal"><span class="pre">$switch</span></code></a> for more information on the <code class="docutils literal"><span class="pre">$switch</span></code>
aggregation operator.</dd>
</dl>
<p>After the command, the collection contains the following documents:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;tests&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="mi">95</span><span class="p">,</span> <span class="mi">92</span><span class="p">,</span> <span class="mi">90</span> <span class="p">],</span> <span class="s2">&quot;lastUpdate&quot;</span> <span class="o">:</span> <span class="nx">ISODate</span><span class="p">(</span><span class="s2">&quot;2020-01-24T17:29:35.340Z&quot;</span><span class="p">),</span> <span class="s2">&quot;average&quot;</span> <span class="o">:</span> <span class="mi">92</span><span class="p">,</span> <span class="s2">&quot;grade&quot;</span> <span class="o">:</span> <span class="s2">&quot;A&quot;</span> <span class="p">}</span>
<span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s2">&quot;tests&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="mi">94</span><span class="p">,</span> <span class="mi">88</span><span class="p">,</span> <span class="mi">90</span> <span class="p">],</span> <span class="s2">&quot;lastUpdate&quot;</span> <span class="o">:</span> <span class="nx">ISODate</span><span class="p">(</span><span class="s2">&quot;2020-01-24T17:29:35.340Z&quot;</span><span class="p">),</span> <span class="s2">&quot;average&quot;</span> <span class="o">:</span> <span class="mi">90</span><span class="p">,</span> <span class="s2">&quot;grade&quot;</span> <span class="o">:</span> <span class="s2">&quot;A&quot;</span> <span class="p">}</span>
<span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">3</span><span class="p">,</span> <span class="s2">&quot;tests&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="mi">70</span><span class="p">,</span> <span class="mi">75</span><span class="p">,</span> <span class="mi">82</span> <span class="p">],</span> <span class="s2">&quot;lastUpdate&quot;</span> <span class="o">:</span> <span class="nx">ISODate</span><span class="p">(</span><span class="s2">&quot;2020-01-24T17:29:35.340Z&quot;</span><span class="p">),</span> <span class="s2">&quot;average&quot;</span> <span class="o">:</span> <span class="mi">75</span><span class="p">,</span> <span class="s2">&quot;grade&quot;</span> <span class="o">:</span> <span class="s2">&quot;C&quot;</span> <span class="p">}</span>
</pre></div>
</div>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="../../tutorial/update-documents-with-aggregation-pipeline.html"><span class="doc">Updates with Aggregation Pipeline</span></a></p>
</div>
</div>
</div>
</div>
<div class="section" id="specify-arrayfilters-for-array-update-operations">
<span id="update-arrayfilters"></span><h3>Specify <code class="docutils literal"><span class="pre">arrayFilters</span></code> for Array Update Operations<a class="headerlink" href="#specify-arrayfilters-for-array-update-operations" title="Permalink to this headline">¶</a></h3>
<p>In the update document, use the <a class="reference internal" href="../operator/update/positional-filtered.html#up._S_[&lt;identifier&gt;]" title="$[&lt;identifier&gt;]"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$[&lt;identifier&gt;]</span></code></a> filtered
positional operator to define an identifier, which you then reference
in the array filter documents. You cannot have an array filter
document for an identifier if the identifier is not included in the
update document.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The <code class="docutils literal"><span class="pre">&lt;identifier&gt;</span></code> must begin with a lowercase letter and
contain only alphanumeric characters.</p>
</div>
<p>You can include the same identifier multiple times in the update
document; however, for each distinct identifier (<code class="docutils literal"><span class="pre">$[identifier]</span></code>)
in the update document, you must specify <strong>exactly one</strong>
corresponding array filter document. That is, you cannot specify
multiple array filter documents for the same identifier. For
example, if the update statement includes the identifier <code class="docutils literal"><span class="pre">x</span></code>
(possibly multiple times), you cannot specify the following for
<code class="docutils literal"><span class="pre">arrayFilters</span></code> that includes 2 separate filter documents for <code class="docutils literal"><span class="pre">x</span></code>:</p>
<div class="button-code-block">
<div class="button-row">
</div>
<div class="highlight-javascript"><div class="highlight"><pre><span></span><span class="c1">// INVALID</span>

<span class="p">[</span>
  <span class="p">{</span> <span class="s2">&quot;x.a&quot;</span><span class="o">:</span> <span class="p">{</span> <span class="nx">$gt</span><span class="o">:</span> <span class="mi">85</span> <span class="p">}</span> <span class="p">},</span>
  <span class="p">{</span> <span class="s2">&quot;x.b&quot;</span><span class="o">:</span> <span class="p">{</span> <span class="nx">$gt</span><span class="o">:</span> <span class="mi">80</span> <span class="p">}</span> <span class="p">}</span>
<span class="p">]</span>
</pre></div>
</div>
</div>
<p>However, you can specify compound conditions on the same identifier
in a single filter document, such as in the following examples:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="c1">// Example 1</span>
<span class="p">[</span>
  <span class="p">{</span> <span class="nx">$or</span><span class="o">:</span> <span class="p">[{</span><span class="s2">&quot;x.a&quot;</span><span class="o">:</span> <span class="p">{</span><span class="nx">$gt</span><span class="o">:</span> <span class="mi">85</span><span class="p">}},</span> <span class="p">{</span><span class="s2">&quot;x.b&quot;</span><span class="o">:</span> <span class="p">{</span><span class="nx">$gt</span><span class="o">:</span> <span class="mi">80</span><span class="p">}}]</span> <span class="p">}</span>
<span class="p">]</span>
<span class="c1">// Example 2</span>
<span class="p">[</span>
  <span class="p">{</span> <span class="nx">$and</span><span class="o">:</span> <span class="p">[{</span><span class="s2">&quot;x.a&quot;</span><span class="o">:</span> <span class="p">{</span><span class="nx">$gt</span><span class="o">:</span> <span class="mi">85</span><span class="p">}},</span> <span class="p">{</span><span class="s2">&quot;x.b&quot;</span><span class="o">:</span> <span class="p">{</span><span class="nx">$gt</span><span class="o">:</span> <span class="mi">80</span><span class="p">}}]</span> <span class="p">}</span>
<span class="p">]</span>
<span class="c1">// Example 3</span>
<span class="p">[</span>
  <span class="p">{</span> <span class="s2">&quot;x.a&quot;</span><span class="o">:</span> <span class="p">{</span> <span class="nx">$gt</span><span class="o">:</span> <span class="mi">85</span> <span class="p">},</span> <span class="s2">&quot;x.b&quot;</span><span class="o">:</span> <span class="p">{</span> <span class="nx">$gt</span><span class="o">:</span> <span class="mi">80</span> <span class="p">}</span> <span class="p">}</span>
<span class="p">]</span>
</pre></div>
</div>
</div>
<p><code class="docutils literal"><span class="pre">arrayFilters</span></code> is not available for updates that use an
aggregation pipeline.</p>
<div class="section" id="update-elements-match-arrayfilters-criteria">
<h4>Update Elements Match <code class="docutils literal"><span class="pre">arrayFilters</span></code> Criteria<a class="headerlink" href="#update-elements-match-arrayfilters-criteria" title="Permalink to this headline">¶</a></h4>
<p>To update all array elements which match a specified criteria, use the
<a class="reference internal" href="#update-array-filters"><span class="std std-ref">arrayFilters</span></a> parameter.</p>
<p>From the <a class="reference internal" href="../program/mongo.html#bin.mongo" title="bin.mongo"><code class="xref mongodb mongodb-binary docutils literal"><span class="pre">mongo</span></code></a> shell, create a <code class="docutils literal"><span class="pre">students</span></code>
collection with the following documents:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">students</span><span class="p">.</span><span class="nx">insertMany</span><span class="p">([</span>
   <span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;grades&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="mi">95</span><span class="p">,</span> <span class="mi">92</span><span class="p">,</span> <span class="mi">90</span> <span class="p">]</span> <span class="p">},</span>
   <span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s2">&quot;grades&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="mi">98</span><span class="p">,</span> <span class="mi">100</span><span class="p">,</span> <span class="mi">102</span> <span class="p">]</span> <span class="p">},</span>
   <span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">3</span><span class="p">,</span> <span class="s2">&quot;grades&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="mi">95</span><span class="p">,</span> <span class="mi">110</span><span class="p">,</span> <span class="mi">100</span> <span class="p">]</span> <span class="p">}</span>
<span class="p">])</span>
</pre></div>
</div>
</div>
<p>To update all elements that are greater than or equal to <code class="docutils literal"><span class="pre">100</span></code> in the
<code class="docutils literal"><span class="pre">grades</span></code> array, use the filtered positional operator
<a class="reference internal" href="../operator/update/positional-filtered.html#up._S_[&lt;identifier&gt;]" title="$[&lt;identifier&gt;]"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$[&lt;identifier&gt;]</span></code></a> with the <code class="docutils literal"><span class="pre">arrayFilters</span></code> option:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">students</span><span class="p">.</span><span class="nx">update</span><span class="p">(</span>
   <span class="p">{</span> <span class="nx">grades</span><span class="o">:</span> <span class="p">{</span> <span class="nx">$gte</span><span class="o">:</span> <span class="mi">100</span> <span class="p">}</span> <span class="p">},</span>
   <span class="p">{</span> <span class="nx">$set</span><span class="o">:</span> <span class="p">{</span> <span class="s2">&quot;grades.$[element]&quot;</span> <span class="o">:</span> <span class="mi">100</span> <span class="p">}</span> <span class="p">},</span>
   <span class="p">{</span>
     <span class="nx">multi</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
     <span class="nx">arrayFilters</span><span class="o">:</span> <span class="p">[</span> <span class="p">{</span> <span class="s2">&quot;element&quot;</span><span class="o">:</span> <span class="p">{</span> <span class="nx">$gte</span><span class="o">:</span> <span class="mi">100</span> <span class="p">}</span> <span class="p">}</span> <span class="p">]</span>
   <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<p>After the operation, the collection contains the following documents:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;grades&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="mi">95</span><span class="p">,</span> <span class="mi">92</span><span class="p">,</span> <span class="mi">90</span> <span class="p">]</span> <span class="p">}</span>
<span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s2">&quot;grades&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="mi">98</span><span class="p">,</span> <span class="mi">100</span><span class="p">,</span> <span class="mi">100</span> <span class="p">]</span> <span class="p">}</span>
<span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">3</span><span class="p">,</span> <span class="s2">&quot;grades&quot;</span> <span class="o">:</span> <span class="p">[</span> <span class="mi">95</span><span class="p">,</span> <span class="mi">100</span><span class="p">,</span> <span class="mi">100</span> <span class="p">]</span> <span class="p">}</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="update-specific-elements-of-an-array-of-documents">
<h4>Update Specific Elements of an Array of Documents<a class="headerlink" href="#update-specific-elements-of-an-array-of-documents" title="Permalink to this headline">¶</a></h4>
<p>You can also use the <a class="reference internal" href="#update-array-filters"><span class="std std-ref">arrayFilters</span></a>
parameter to update specific document fields within an array of
documents.</p>
<p>From the <a class="reference internal" href="../program/mongo.html#bin.mongo" title="bin.mongo"><code class="xref mongodb mongodb-binary docutils literal"><span class="pre">mongo</span></code></a> shell, create a <code class="docutils literal"><span class="pre">students2</span></code>
collection with the following documents:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">students2</span><span class="p">.</span><span class="nx">insertMany</span><span class="p">([</span>
  <span class="p">{</span>
    <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span>
    <span class="s2">&quot;grades&quot;</span> <span class="o">:</span> <span class="p">[</span>
       <span class="p">{</span> <span class="s2">&quot;grade&quot;</span> <span class="o">:</span> <span class="mi">80</span><span class="p">,</span> <span class="s2">&quot;mean&quot;</span> <span class="o">:</span> <span class="mi">75</span><span class="p">,</span> <span class="s2">&quot;std&quot;</span> <span class="o">:</span> <span class="mi">6</span> <span class="p">},</span>
       <span class="p">{</span> <span class="s2">&quot;grade&quot;</span> <span class="o">:</span> <span class="mi">85</span><span class="p">,</span> <span class="s2">&quot;mean&quot;</span> <span class="o">:</span> <span class="mi">90</span><span class="p">,</span> <span class="s2">&quot;std&quot;</span> <span class="o">:</span> <span class="mi">4</span> <span class="p">},</span>
       <span class="p">{</span> <span class="s2">&quot;grade&quot;</span> <span class="o">:</span> <span class="mi">85</span><span class="p">,</span> <span class="s2">&quot;mean&quot;</span> <span class="o">:</span> <span class="mi">85</span><span class="p">,</span> <span class="s2">&quot;std&quot;</span> <span class="o">:</span> <span class="mi">6</span> <span class="p">}</span>
    <span class="p">]</span>
  <span class="p">}</span>
  <span class="p">{</span>
     <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">2</span><span class="p">,</span>
     <span class="s2">&quot;grades&quot;</span> <span class="o">:</span> <span class="p">[</span>
        <span class="p">{</span> <span class="s2">&quot;grade&quot;</span> <span class="o">:</span> <span class="mi">90</span><span class="p">,</span> <span class="s2">&quot;mean&quot;</span> <span class="o">:</span> <span class="mi">75</span><span class="p">,</span> <span class="s2">&quot;std&quot;</span> <span class="o">:</span> <span class="mi">6</span> <span class="p">},</span>
        <span class="p">{</span> <span class="s2">&quot;grade&quot;</span> <span class="o">:</span> <span class="mi">87</span><span class="p">,</span> <span class="s2">&quot;mean&quot;</span> <span class="o">:</span> <span class="mi">90</span><span class="p">,</span> <span class="s2">&quot;std&quot;</span> <span class="o">:</span> <span class="mi">3</span> <span class="p">},</span>
        <span class="p">{</span> <span class="s2">&quot;grade&quot;</span> <span class="o">:</span> <span class="mi">85</span><span class="p">,</span> <span class="s2">&quot;mean&quot;</span> <span class="o">:</span> <span class="mi">85</span><span class="p">,</span> <span class="s2">&quot;std&quot;</span> <span class="o">:</span> <span class="mi">4</span> <span class="p">}</span>
     <span class="p">]</span>
  <span class="p">}</span>
<span class="p">])</span>
</pre></div>
</div>
</div>
<p>To modify the value of the <code class="docutils literal"><span class="pre">mean</span></code> field for all elements in the
<code class="docutils literal"><span class="pre">grades</span></code> array where the grade is greater than or equal to <code class="docutils literal"><span class="pre">85</span></code>,
use the filtered positional operator <a class="reference internal" href="../operator/update/positional-filtered.html#up._S_[&lt;identifier&gt;]" title="$[&lt;identifier&gt;]"><code class="xref mongodb mongodb-update docutils literal"><span class="pre">$[&lt;identifier&gt;]</span></code></a> with
the <code class="docutils literal"><span class="pre">arrayFilters</span></code>:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">students2</span><span class="p">.</span><span class="nx">update</span><span class="p">(</span>
   <span class="p">{</span> <span class="p">},</span>
   <span class="p">{</span> <span class="nx">$set</span><span class="o">:</span> <span class="p">{</span> <span class="s2">&quot;grades.$[elem].mean&quot;</span> <span class="o">:</span> <span class="mi">100</span> <span class="p">}</span> <span class="p">},</span>
   <span class="p">{</span>
     <span class="nx">multi</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
     <span class="nx">arrayFilters</span><span class="o">:</span> <span class="p">[</span> <span class="p">{</span> <span class="s2">&quot;elem.grade&quot;</span><span class="o">:</span> <span class="p">{</span> <span class="nx">$gte</span><span class="o">:</span> <span class="mi">85</span> <span class="p">}</span> <span class="p">}</span> <span class="p">]</span>
   <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<p>After the operation, the collection has the following documents:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="p">{</span>
   <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span>
   <span class="s2">&quot;grades&quot;</span> <span class="o">:</span> <span class="p">[</span>
      <span class="p">{</span> <span class="s2">&quot;grade&quot;</span> <span class="o">:</span> <span class="mi">80</span><span class="p">,</span> <span class="s2">&quot;mean&quot;</span> <span class="o">:</span> <span class="mi">75</span><span class="p">,</span> <span class="s2">&quot;std&quot;</span> <span class="o">:</span> <span class="mi">6</span> <span class="p">},</span>
      <span class="p">{</span> <span class="s2">&quot;grade&quot;</span> <span class="o">:</span> <span class="mi">85</span><span class="p">,</span> <span class="s2">&quot;mean&quot;</span> <span class="o">:</span> <span class="mi">100</span><span class="p">,</span> <span class="s2">&quot;std&quot;</span> <span class="o">:</span> <span class="mi">4</span> <span class="p">},</span>
      <span class="p">{</span> <span class="s2">&quot;grade&quot;</span> <span class="o">:</span> <span class="mi">85</span><span class="p">,</span> <span class="s2">&quot;mean&quot;</span> <span class="o">:</span> <span class="mi">100</span><span class="p">,</span> <span class="s2">&quot;std&quot;</span> <span class="o">:</span> <span class="mi">6</span> <span class="p">}</span>
   <span class="p">]</span>
<span class="p">}</span>
<span class="p">{</span>
   <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">2</span><span class="p">,</span>
   <span class="s2">&quot;grades&quot;</span> <span class="o">:</span> <span class="p">[</span>
      <span class="p">{</span> <span class="s2">&quot;grade&quot;</span> <span class="o">:</span> <span class="mi">90</span><span class="p">,</span> <span class="s2">&quot;mean&quot;</span> <span class="o">:</span> <span class="mi">100</span><span class="p">,</span> <span class="s2">&quot;std&quot;</span> <span class="o">:</span> <span class="mi">6</span> <span class="p">},</span>
      <span class="p">{</span> <span class="s2">&quot;grade&quot;</span> <span class="o">:</span> <span class="mi">87</span><span class="p">,</span> <span class="s2">&quot;mean&quot;</span> <span class="o">:</span> <span class="mi">100</span><span class="p">,</span> <span class="s2">&quot;std&quot;</span> <span class="o">:</span> <span class="mi">3</span> <span class="p">},</span>
      <span class="p">{</span> <span class="s2">&quot;grade&quot;</span> <span class="o">:</span> <span class="mi">85</span><span class="p">,</span> <span class="s2">&quot;mean&quot;</span> <span class="o">:</span> <span class="mi">100</span><span class="p">,</span> <span class="s2">&quot;std&quot;</span> <span class="o">:</span> <span class="mi">4</span> <span class="p">}</span>
   <span class="p">]</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="section" id="specify-hint-for-update-operations">
<span id="ex-update-hint"></span><h3>Specify <code class="docutils literal"><span class="pre">hint</span></code> for Update Operations<a class="headerlink" href="#specify-hint-for-update-operations" title="Permalink to this headline">¶</a></h3>
<div class="versionadded">
<p><span class="versionmodified">New in version 4.2.</span></p>
</div>
<p>From the <a class="reference internal" href="../program/mongo.html#bin.mongo" title="bin.mongo"><code class="xref mongodb mongodb-binary docutils literal"><span class="pre">mongo</span></code></a> shell, create a <code class="docutils literal"><span class="pre">members</span></code>
collection with the following documents:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">members</span><span class="p">.</span><span class="nx">insertMany</span><span class="p">([</span>
   <span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;member&quot;</span> <span class="o">:</span> <span class="s2">&quot;abc123&quot;</span><span class="p">,</span> <span class="s2">&quot;status&quot;</span> <span class="o">:</span> <span class="s2">&quot;P&quot;</span><span class="p">,</span> <span class="s2">&quot;points&quot;</span> <span class="o">:</span>  <span class="mi">0</span><span class="p">,</span>  <span class="s2">&quot;misc1&quot;</span> <span class="o">:</span> <span class="kc">null</span><span class="p">,</span> <span class="s2">&quot;misc2&quot;</span> <span class="o">:</span> <span class="kc">null</span> <span class="p">},</span>
   <span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s2">&quot;member&quot;</span> <span class="o">:</span> <span class="s2">&quot;xyz123&quot;</span><span class="p">,</span> <span class="s2">&quot;status&quot;</span> <span class="o">:</span> <span class="s2">&quot;A&quot;</span><span class="p">,</span> <span class="s2">&quot;points&quot;</span> <span class="o">:</span> <span class="mi">60</span><span class="p">,</span>  <span class="s2">&quot;misc1&quot;</span> <span class="o">:</span> <span class="s2">&quot;reminder: ping me at 100pts&quot;</span><span class="p">,</span> <span class="s2">&quot;misc2&quot;</span> <span class="o">:</span> <span class="s2">&quot;Some random comment&quot;</span> <span class="p">},</span>
   <span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">3</span><span class="p">,</span> <span class="s2">&quot;member&quot;</span> <span class="o">:</span> <span class="s2">&quot;lmn123&quot;</span><span class="p">,</span> <span class="s2">&quot;status&quot;</span> <span class="o">:</span> <span class="s2">&quot;P&quot;</span><span class="p">,</span> <span class="s2">&quot;points&quot;</span> <span class="o">:</span>  <span class="mi">0</span><span class="p">,</span>  <span class="s2">&quot;misc1&quot;</span> <span class="o">:</span> <span class="kc">null</span><span class="p">,</span> <span class="s2">&quot;misc2&quot;</span> <span class="o">:</span> <span class="kc">null</span> <span class="p">},</span>
   <span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">4</span><span class="p">,</span> <span class="s2">&quot;member&quot;</span> <span class="o">:</span> <span class="s2">&quot;pqr123&quot;</span><span class="p">,</span> <span class="s2">&quot;status&quot;</span> <span class="o">:</span> <span class="s2">&quot;D&quot;</span><span class="p">,</span> <span class="s2">&quot;points&quot;</span> <span class="o">:</span> <span class="mi">20</span><span class="p">,</span>  <span class="s2">&quot;misc1&quot;</span> <span class="o">:</span> <span class="s2">&quot;Deactivated&quot;</span><span class="p">,</span> <span class="s2">&quot;misc2&quot;</span> <span class="o">:</span> <span class="kc">null</span> <span class="p">},</span>
   <span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">5</span><span class="p">,</span> <span class="s2">&quot;member&quot;</span> <span class="o">:</span> <span class="s2">&quot;ijk123&quot;</span><span class="p">,</span> <span class="s2">&quot;status&quot;</span> <span class="o">:</span> <span class="s2">&quot;P&quot;</span><span class="p">,</span> <span class="s2">&quot;points&quot;</span> <span class="o">:</span>  <span class="mi">0</span><span class="p">,</span>  <span class="s2">&quot;misc1&quot;</span> <span class="o">:</span> <span class="kc">null</span><span class="p">,</span> <span class="s2">&quot;misc2&quot;</span> <span class="o">:</span> <span class="kc">null</span> <span class="p">},</span>
   <span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">6</span><span class="p">,</span> <span class="s2">&quot;member&quot;</span> <span class="o">:</span> <span class="s2">&quot;cde123&quot;</span><span class="p">,</span> <span class="s2">&quot;status&quot;</span> <span class="o">:</span> <span class="s2">&quot;A&quot;</span><span class="p">,</span> <span class="s2">&quot;points&quot;</span> <span class="o">:</span> <span class="mi">86</span><span class="p">,</span>  <span class="s2">&quot;misc1&quot;</span> <span class="o">:</span> <span class="s2">&quot;reminder: ping me at 100pts&quot;</span><span class="p">,</span> <span class="s2">&quot;misc2&quot;</span> <span class="o">:</span> <span class="s2">&quot;Some random comment&quot;</span> <span class="p">}</span>
<span class="p">])</span>
</pre></div>
</div>
</div>
<p>Create the following indexes on the collection:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">members</span><span class="p">.</span><span class="nx">createIndex</span><span class="p">(</span> <span class="p">{</span> <span class="nx">status</span><span class="o">:</span> <span class="mi">1</span> <span class="p">}</span> <span class="p">)</span>
<span class="nx">db</span><span class="p">.</span><span class="nx">members</span><span class="p">.</span><span class="nx">createIndex</span><span class="p">(</span> <span class="p">{</span> <span class="nx">points</span><span class="o">:</span> <span class="mi">1</span> <span class="p">}</span> <span class="p">)</span>
</pre></div>
</div>
</div>
<p>The following update operation explicitly <a class="reference internal" href="#update-hint"><span class="std std-ref">hints</span></a> to
use the index <code class="docutils literal"><span class="pre">{status:</span> <span class="pre">1</span> <span class="pre">}</span></code>:</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If you specify an index that does not exist, the operation errors.</p>
</div>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">members</span><span class="p">.</span><span class="nx">update</span><span class="p">(</span>
   <span class="p">{</span> <span class="nx">points</span><span class="o">:</span> <span class="p">{</span> <span class="nx">$lte</span><span class="o">:</span> <span class="mi">20</span> <span class="p">},</span> <span class="nx">status</span><span class="o">:</span> <span class="s2">&quot;P&quot;</span> <span class="p">},</span>     <span class="c1">// Query parameter</span>
   <span class="p">{</span> <span class="nx">$set</span><span class="o">:</span> <span class="p">{</span> <span class="nx">misc1</span><span class="o">:</span> <span class="s2">&quot;Need to activate&quot;</span> <span class="p">}</span> <span class="p">},</span>   <span class="c1">// Update document</span>
   <span class="p">{</span> <span class="nx">multi</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">hint</span><span class="o">:</span> <span class="p">{</span> <span class="nx">status</span><span class="o">:</span> <span class="mi">1</span> <span class="p">}</span> <span class="p">}</span>       <span class="c1">// Options</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<p>The update command returns the following:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">WriteResult</span><span class="p">({</span> <span class="s2">&quot;nMatched&quot;</span> <span class="o">:</span> <span class="mi">3</span><span class="p">,</span> <span class="s2">&quot;nUpserted&quot;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">,</span> <span class="s2">&quot;nModified&quot;</span> <span class="o">:</span> <span class="mi">3</span> <span class="p">})</span>
</pre></div>
</div>
</div>
<p>To see the index used, run <a class="reference internal" href="../command/explain.html#dbcmd.explain" title="explain"><code class="xref mongodb mongodb-dbcommand docutils literal"><span class="pre">explain</span></code></a> on the operation:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">members</span><span class="p">.</span><span class="nx">explain</span><span class="p">().</span><span class="nx">update</span><span class="p">(</span>
   <span class="p">{</span> <span class="s2">&quot;points&quot;</span><span class="o">:</span> <span class="p">{</span> <span class="nx">$lte</span><span class="o">:</span> <span class="mi">20</span> <span class="p">},</span> <span class="s2">&quot;status&quot;</span><span class="o">:</span> <span class="s2">&quot;P&quot;</span> <span class="p">},</span>
   <span class="p">{</span> <span class="nx">$set</span><span class="o">:</span> <span class="p">{</span> <span class="s2">&quot;misc1&quot;</span><span class="o">:</span> <span class="s2">&quot;Need to activate&quot;</span> <span class="p">}</span> <span class="p">},</span>
   <span class="p">{</span> <span class="nx">multi</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">hint</span><span class="o">:</span> <span class="p">{</span> <span class="nx">status</span><span class="o">:</span> <span class="mi">1</span> <span class="p">}</span> <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<p>The <a class="reference internal" href="db.collection.explain.html#db.collection.explain" title="db.collection.explain"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.explain().update()</span></code></a>
does not modify the documents.</p>
</div>
<div class="section" id="override-default-write-concern">
<span id="example-update-write-concern"></span><h3>Override Default Write Concern<a class="headerlink" href="#override-default-write-concern" title="Permalink to this headline">¶</a></h3>
<p>The following operation on a replica set specifies a <a class="reference internal" href="../write-concern.html"><span class="doc">write
concern</span></a> of <code class="docutils literal"><span class="pre">&quot;w:</span> <span class="pre">majority&quot;</span></code> with a
<code class="docutils literal"><span class="pre">wtimeout</span></code> of 5000 milliseconds such that the method returns after
the write propagates to a majority of the voting replica set members or
the method times out after 5 seconds.</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">books</span><span class="p">.</span><span class="nx">update</span><span class="p">(</span>
   <span class="p">{</span> <span class="nx">stock</span><span class="o">:</span> <span class="p">{</span> <span class="nx">$lte</span><span class="o">:</span> <span class="mi">10</span> <span class="p">}</span> <span class="p">},</span>
   <span class="p">{</span> <span class="nx">$set</span><span class="o">:</span> <span class="p">{</span> <span class="nx">reorder</span><span class="o">:</span> <span class="kc">true</span> <span class="p">}</span> <span class="p">},</span>
   <span class="p">{</span>
     <span class="nx">multi</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
     <span class="nx">writeConcern</span><span class="o">:</span> <span class="p">{</span> <span class="nx">w</span><span class="o">:</span> <span class="s2">&quot;majority&quot;</span><span class="p">,</span> <span class="nx">wtimeout</span><span class="o">:</span> <span class="mi">5000</span> <span class="p">}</span>
   <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="specify-collation">
<span id="example-update-collation"></span><h3>Specify Collation<a class="headerlink" href="#specify-collation" title="Permalink to this headline">¶</a></h3>
<p>Specifies the <a class="reference internal" href="../bson-type-comparison-order.html#collation"><span class="std std-ref">collation</span></a>  to use for the operation.</p>
<p><a class="reference internal" href="../collation.html"><span class="doc">Collation</span></a> allows users to specify
language-specific rules for string comparison, such as rules for
lettercase and accent marks.</p>
<p>The collation option has the following syntax:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">collation</span><span class="o">:</span> <span class="p">{</span>
   <span class="nx">locale</span><span class="o">:</span> <span class="o">&lt;</span><span class="nx">string</span><span class="o">&gt;</span><span class="p">,</span>
   <span class="nx">caseLevel</span><span class="o">:</span> <span class="o">&lt;</span><span class="kr">boolean</span><span class="o">&gt;</span><span class="p">,</span>
   <span class="nx">caseFirst</span><span class="o">:</span> <span class="o">&lt;</span><span class="nx">string</span><span class="o">&gt;</span><span class="p">,</span>
   <span class="nx">strength</span><span class="o">:</span> <span class="o">&lt;</span><span class="kr">int</span><span class="o">&gt;</span><span class="p">,</span>
   <span class="nx">numericOrdering</span><span class="o">:</span> <span class="o">&lt;</span><span class="kr">boolean</span><span class="o">&gt;</span><span class="p">,</span>
   <span class="nx">alternate</span><span class="o">:</span> <span class="o">&lt;</span><span class="nx">string</span><span class="o">&gt;</span><span class="p">,</span>
   <span class="nx">maxVariable</span><span class="o">:</span> <span class="o">&lt;</span><span class="nx">string</span><span class="o">&gt;</span><span class="p">,</span>
   <span class="nx">backwards</span><span class="o">:</span> <span class="o">&lt;</span><span class="kr">boolean</span><span class="o">&gt;</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<p>When specifying collation, the <code class="docutils literal"><span class="pre">locale</span></code> field is mandatory; all
other collation fields are optional. For descriptions of the fields,
see <a class="reference internal" href="../collation.html#collation-document-fields"><span class="std std-ref">Collation Document</span></a>.</p>
<p>If the collation is unspecified but the collection has a
default collation (see <a class="reference internal" href="db.createCollection.html#db.createCollection" title="db.createCollection()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.createCollection()</span></code></a>), the
operation uses the collation specified for the collection.</p>
<p>If no collation is specified for the collection or for the
operations, MongoDB uses the simple binary comparison used in prior
versions for string comparisons.</p>
<p>You cannot specify multiple collations for an operation. For
example, you cannot specify different collations per field, or if
performing a find with a sort, you cannot use one collation for the
find and another for the sort.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.4.</span></p>
</div>
<p>From the <a class="reference internal" href="../program/mongo.html#bin.mongo" title="bin.mongo"><code class="xref mongodb mongodb-binary docutils literal"><span class="pre">mongo</span></code></a> shell, create a collection named
<code class="docutils literal"><span class="pre">myColl</span></code> with the following documents:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">myColl</span><span class="p">.</span><span class="nx">insertMany</span><span class="p">(</span>
  <span class="p">[</span>
    <span class="p">{</span> <span class="nx">_id</span><span class="o">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nx">category</span><span class="o">:</span> <span class="s2">&quot;café&quot;</span><span class="p">,</span> <span class="nx">status</span><span class="o">:</span> <span class="s2">&quot;A&quot;</span> <span class="p">},</span>
    <span class="p">{</span> <span class="nx">_id</span><span class="o">:</span> <span class="mi">2</span><span class="p">,</span> <span class="nx">category</span><span class="o">:</span> <span class="s2">&quot;cafe&quot;</span><span class="p">,</span> <span class="nx">status</span><span class="o">:</span> <span class="s2">&quot;a&quot;</span> <span class="p">},</span>
    <span class="p">{</span> <span class="nx">_id</span><span class="o">:</span> <span class="mi">3</span><span class="p">,</span> <span class="nx">category</span><span class="o">:</span> <span class="s2">&quot;cafE&quot;</span><span class="p">,</span> <span class="nx">status</span><span class="o">:</span> <span class="s2">&quot;a&quot;</span> <span class="p">}</span>
  <span class="p">])</span>
</pre></div>
</div>
</div>
<p>The following operation includes the <a class="reference internal" href="../bson-type-comparison-order.html#collation"><span class="std std-ref">collation</span></a>
option and sets <code class="docutils literal"><span class="pre">multi</span></code> to <code class="docutils literal"><span class="pre">true</span></code> to update all matching documents:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">db</span><span class="p">.</span><span class="nx">myColl</span><span class="p">.</span><span class="nx">update</span><span class="p">(</span>
   <span class="p">{</span> <span class="nx">category</span><span class="o">:</span> <span class="s2">&quot;cafe&quot;</span> <span class="p">},</span>
   <span class="p">{</span> <span class="nx">$set</span><span class="o">:</span> <span class="p">{</span> <span class="nx">status</span><span class="o">:</span> <span class="s2">&quot;Updated&quot;</span> <span class="p">}</span> <span class="p">},</span>
   <span class="p">{</span>
     <span class="nx">collation</span><span class="o">:</span> <span class="p">{</span> <span class="nx">locale</span><span class="o">:</span> <span class="s2">&quot;fr&quot;</span><span class="p">,</span> <span class="nx">strength</span><span class="o">:</span> <span class="mi">1</span> <span class="p">},</span>
     <span class="nx">multi</span><span class="o">:</span> <span class="kc">true</span>
   <span class="p">}</span>
<span class="p">);</span>
</pre></div>
</div>
</div>
<p>The <a class="reference internal" href="#writeresults-update"><span class="std std-ref">write result</span></a> of the operation returns the following document, indicating that all three documents in the
collection were updated:</p>
<div class="button-code-block">
<div class="button-row">
</div>
<div class="highlight-none"><div class="highlight"><pre><span></span>WriteResult({ &quot;nMatched&quot; : 3, &quot;nUpserted&quot; : 0, &quot;nModified&quot; : 3 })
</pre></div>
</div>
</div>
<p>After the operation, the collection contains the following documents:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;category&quot;</span> <span class="o">:</span> <span class="s2">&quot;café&quot;</span><span class="p">,</span> <span class="s2">&quot;status&quot;</span> <span class="o">:</span> <span class="s2">&quot;Updated&quot;</span> <span class="p">}</span>
<span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s2">&quot;category&quot;</span> <span class="o">:</span> <span class="s2">&quot;cafe&quot;</span><span class="p">,</span> <span class="s2">&quot;status&quot;</span> <span class="o">:</span> <span class="s2">&quot;Updated&quot;</span> <span class="p">}</span>
<span class="p">{</span> <span class="s2">&quot;_id&quot;</span> <span class="o">:</span> <span class="mi">3</span><span class="p">,</span> <span class="s2">&quot;category&quot;</span> <span class="o">:</span> <span class="s2">&quot;cafE&quot;</span><span class="p">,</span> <span class="s2">&quot;status&quot;</span> <span class="o">:</span> <span class="s2">&quot;Updated&quot;</span> <span class="p">}</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="section" id="writeresult">
<span id="writeresults-update"></span><h2>WriteResult<a class="headerlink" href="#writeresult" title="Permalink to this headline">¶</a></h2>
<div class="section" id="successful-results">
<h3>Successful Results<a class="headerlink" href="#successful-results" title="Permalink to this headline">¶</a></h3>
<p>The <a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> method returns a
<a class="reference internal" href="WriteResult.html#WriteResult" title="WriteResult"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">WriteResult</span></code></a> object that contains the status of the operation.
Upon success, the <a class="reference internal" href="WriteResult.html#WriteResult" title="WriteResult"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">WriteResult</span></code></a> object contains the number of
documents that matched the query condition, the number of documents
inserted by the update, and the number of documents modified:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">WriteResult</span><span class="p">({</span> <span class="s2">&quot;nMatched&quot;</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;nUpserted&quot;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">,</span> <span class="s2">&quot;nModified&quot;</span> <span class="o">:</span> <span class="mi">1</span> <span class="p">})</span>
</pre></div>
</div>
</div>
<div class="admonition-see admonition">
<p class="first admonition-title">See</p>
<p class="last"><a class="reference internal" href="WriteResult.html#WriteResult.nMatched" title="WriteResult.nMatched"><code class="xref mongodb mongodb-data docutils literal"><span class="pre">WriteResult.nMatched</span></code></a>, <a class="reference internal" href="WriteResult.html#WriteResult.nUpserted" title="WriteResult.nUpserted"><code class="xref mongodb mongodb-data docutils literal"><span class="pre">WriteResult.nUpserted</span></code></a>,
<a class="reference internal" href="WriteResult.html#WriteResult.nModified" title="WriteResult.nModified"><code class="xref mongodb mongodb-data docutils literal"><span class="pre">WriteResult.nModified</span></code></a></p>
</div>
</div>
<div class="section" id="write-concern-errors">
<h3>Write Concern Errors<a class="headerlink" href="#write-concern-errors" title="Permalink to this headline">¶</a></h3>
<p>If the <a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> method encounters write
concern errors, the results include the
<a class="reference internal" href="WriteResult.html#WriteResult.writeConcernError" title="WriteResult.writeConcernError"><code class="xref mongodb mongodb-data docutils literal"><span class="pre">WriteResult.writeConcernError</span></code></a> field:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">WriteResult</span><span class="p">({</span>
   <span class="s2">&quot;nMatched&quot;</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span>
   <span class="s2">&quot;nUpserted&quot;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">,</span>
   <span class="s2">&quot;nModified&quot;</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span>
   <span class="s2">&quot;writeConcernError&quot;</span> <span class="o">:</span> <span class="p">{</span>
      <span class="s2">&quot;code&quot;</span> <span class="o">:</span> <span class="mi">64</span><span class="p">,</span>
      <span class="s2">&quot;errmsg&quot;</span> <span class="o">:</span> <span class="s2">&quot;waiting for replication timed out at shard-a&quot;</span>
   <span class="p">}</span>
<span class="p">})</span>
</pre></div>
</div>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="WriteResult.hasWriteConcernError.html#WriteResult.hasWriteConcernError" title="WriteResult.hasWriteConcernError()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">WriteResult.hasWriteConcernError()</span></code></a></p>
</div>
</div>
<div class="section" id="errors-unrelated-to-write-concern">
<h3>Errors Unrelated to Write Concern<a class="headerlink" href="#errors-unrelated-to-write-concern" title="Permalink to this headline">¶</a></h3>
<p>If the <a class="reference internal" href="#db.collection.update" title="db.collection.update()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">db.collection.update()</span></code></a> method encounters a non-write
concern error, the results include the <a class="reference internal" href="WriteResult.html#WriteResult.writeError" title="WriteResult.writeError"><code class="xref mongodb mongodb-data docutils literal"><span class="pre">WriteResult.writeError</span></code></a>
field:</p>
<div class="button-code-block">
<div class="button-row">
<a class="code-button--copy code-button" role="button">
copy</a>
</div>
<div class="copyable-code-block highlight-javascript"><div class="highlight"><pre><span></span><span class="nx">WriteResult</span><span class="p">({</span>
   <span class="s2">&quot;nMatched&quot;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">,</span>
   <span class="s2">&quot;nUpserted&quot;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">,</span>
   <span class="s2">&quot;nModified&quot;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">,</span>
   <span class="s2">&quot;writeError&quot;</span> <span class="o">:</span> <span class="p">{</span>
      <span class="s2">&quot;code&quot;</span> <span class="o">:</span> <span class="mi">7</span><span class="p">,</span>
      <span class="s2">&quot;errmsg&quot;</span> <span class="o">:</span> <span class="s2">&quot;could not contact primary for replica set shard-a&quot;</span>
   <span class="p">}</span>
<span class="p">})</span>
</pre></div>
</div>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="WriteResult.hasWriteError.html#WriteResult.hasWriteError" title="WriteResult.hasWriteError()"><code class="xref mongodb mongodb-method docutils literal"><span class="pre">WriteResult.hasWriteError()</span></code></a></p>
</div>
</div>
</div>
</div>

                
    <div id="btnv">
      <span class="btn-arrow-left">&larr; &nbsp;</span>
      <a class="btn-prev-text" href="db.collection.totalSize.html" title="Previous Section: db.collection.totalSize()"><span>db.collection.totalSize()</span></a>
      <a class="btn-next-text" href="db.collection.updateOne.html" title="Next Section: db.collection.updateOne()"><span>db.collection.updateOne()</span></a>
      <span class="btn-arrow-right">&nbsp;&rarr;</span>
    </div>
                  <div class="footer">
                    <div class="copyright">
                      <p>&copy; MongoDB, Inc 2008-present. MongoDB, Mongo, and the leaf logo are registered trademarks of MongoDB, Inc.</p>
                    </div>
                  </div>
              </div></div>
            </div>
        </div>
    </div>
    <div class="right-column">
      <div class="wrapper"> <div id='mongodb-docs-1'>
   <script type='text/javascript'>
      googletag.cmd.push(function() { googletag.display('mongodb-docs-1'); });
   </script>
</div>
            <div class="social">
               <a class="slack-icon" href="https://slackpass.io/mongo-db?jmp=docs" title="https://slackpass.io/mongo-db?jmp=docs"><i class="fab fa-slack" aria-hidden="true"></i></a>
               <a class="twitter-icon" href="https://twitter.com/MongoDB" title="https://twitter.com/MongoDB"><i class="fab fa-twitter-square"></i></a>
               <a class="youtube-icon" href="https://www.youtube.com/user/MongoDB" title="https://www.youtube.com/user/MongoDB"><i class="fab fa-youtube-square"></i></a>
               <a class="facebook-icon" href="https://www.facebook.com/mongodb" title="https://www.facebook.com/mongodb"><i class="fab fa-facebook-square"></i></a>
               <a class="stack-overflow-icon" href="https://stackoverflow.com/tags/mongodb/info" title="https://stackoverflow.com/tags/mongodb/info"><i class="fab fa-stack-overflow" aria-hidden="true"></i></a>
            </div>
        

      </div>
    </div>
    
      <div id="rating-panel"></div>
    
    <div class="clearfix"></div>
  </div>
  

  <script type="text/javascript">
  // Bootstrap array of links that should trigger a full page reload
  window.docsExcludedNav = ['/administration', '/administration/production-checklist', '/administration/indexes-management', '/aggregation', '/applications/geospatial-indexes', '/applications/indexes', '/contributors/getting-started', '/core/2d', '/core/2dsphere', '/core/auditing', '/core/authentication', '/core/authorization', '/core/backups', '/core/read-isolation-consistency-recency', '/core/databases-and-collections', '/core/geohaystack', '/core/index-single', '/core/index-compound', '/core/index-creation', '/core/index-hashed', '/core/index-multikey', '/core/index-partial', '/core/index-sparse', '/core/index-text', '/core/index-ttl', '/core/index-unique', '/core/index-wildcard', '/core/journaling', '/core/kerberos', '/core/map-reduce', '/core/operational-segregation', '/core/query-optimization', '/core/read-preference', '/core/replica-set-architectures', '/core/replica-set-high-availability', '/core/replica-set-members', '/core/replica-set-secondary', '/core/transactions', '/geospatial-queries', '/replication', '/core/sharded-cluster-components', '/core/wiredtiger', '/core/write-operations-atomicity', '/crud', '/indexes', '/installation', '/introduction', '/mongo', '/products/bi-connector', '/reference/command', '/reference/collation', '/text-search', '/tutorial/manage-the-database-profiler', '/core/index-text', '/reference/bson-types', '/reference/configuration-options', '/reference/indexes', '/reference/method', '/reference/operator/aggregation', '/reference/operator/query', '/reference/operator/query-modifier', '/reference/operator/update', '/reference/replication', '/reference/read-concern', '/reference/security', '/reference/sharding', '/reference/write-concern', '/release-notes/2.4', '/release-notes/2.6', '/release-notes/2.8', '/release-notes/3.0', '/release-notes/3.2', '/release-notes/3.4', '/release-notes/3.6', '/release-notes/4.0', '/release-notes/4.2', '/security', '/sharding', '/changeStreams', '/core/zone-sharding', '/core/hashed-sharding', '/core/ranged-sharding', '/storage', '/tutorial/change-sharded-cluster-wiredtiger', '/tutorial/insert-documents', '/tutorial/query-documents', '/tutorial/remove-documents', '/tutorial/update-documents', '/tutorial/enable-authentication', '/tutorial/install-mongodb-on-ubuntu', '/tutorial/install-mongodb-on-windows', '/tutorial/install-mongodb-on-red-hat', '/tutorial/install-mongodb-on-debian', '/tutorial/install-mongodb-on-suse', '/tutorial/install-mongodb-on-amazon', '/tutorial/install-mongodb-enterprise-on-ubuntu', '/tutorial/install-mongodb-enterprise-on-windows', '/tutorial/install-mongodb-enterprise-on-red-hat', '/tutorial/install-mongodb-enterprise-on-debian', '/tutorial/install-mongodb-enterprise-on-suse', '/tutorial/install-mongodb-enterprise-on-amazon', '/tutorial/install-mongodb-on-os-x'];
  </script></body>
</html>